照着这个看的
#include<iostream>
using namespace std;
void printArray(int* array, int len)
{
for (int i = 0; i < len; i++)
{
cout << array[i] << '\t';
}
}
void swap(int* a, int* b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void QuickSort(int* arr,int start,int end)
{
int low = start;
int high = end;
if (low > high)
{
return;
}
while (low != high)
{
while (arr[high] >= arr[start] && low < high)
{
high--;
}
while (arr[low] <= arr[start] && low < high)
{
low++;
}
if (low < high)
{
swap(arr[low], arr[high]);
}
}
swap(arr[start],arr[low]);
QuickSort(arr, start, low - 1);
QuickSort(arr,low + 1,end);
}
int main()
{
int array[] = { 4,1,1,1,1,5,6 };
int len = sizeof(array) / sizeof(int);
printArray(array, len);
cout << '\n';
QuickSort(array,0,len - 1);
printArray(array, len);
return 0;
}