编辑代码

#include <iostream>
//#include<time.h>
using namespace std;


int Paritition1(int A[], int low, int high) {
int pivot = A[low];
while (low < high) {
while (low < high && A[high] >= pivot) {
--high;
}
A[low] = A[high];//这里的A[high]的值一定是小于pivot,所以A[low]当中的值在赋值之后一定也是小于pivot
//因此,不用担心下面这行代码会不会运行,是一定运行,所以不会在同一个地址
//如果是同一个地址,那么就该返回了,返回中间值的地址
while (low < high && A[low] <= pivot) {
++low;
}
A[high]=A[low];
}
A[low] = pivot;
return low;
}

void QuickSort(int A[], int low, int high) //快排母函数
{
if (low < high) 
{
int pivot = Paritition1(A, low, high);
//***************2:左右对称结构******************//
QuickSort(A, low, pivot - 1);
QuickSort(A, pivot + 1, high);
}
}
int main()
{
int len = 6;
int aa[] = {11,9,3,20,56,32};
//int* a = new int[len];
int* a = aa;
/*srand(time(NULL));
for (int i = 0; i < len; i++)
{
a[i] = 10 * rand() / RAND_MAX;
}*/
for (int i = 0; i < len; i++)
cout << ' ' << a[i];
cout << endl;
QuickSort(a, 0 ,len-1);
for (int i = 0; i < len; i++)
cout << ' ' << a[i];
return 0;
}