#include <iostream>
using namespace std;
void quickSort(int a[], int head, int tail)
{
int head2 = head;
int tail2 = tail;
if(tail - head <= 1)
return;
while (head < tail)
{
while (a[head] < a[tail])//找到尾部小于基准的值
tail--;
if(tail <= head)//基准正好是最小元素
continue;
int temp = a[tail];//交换
a[tail] = a[head];
a[head] = temp;
head++;//头指针+1
while(head < tail && a[head] < a[tail])//找头部大于基准的值
head++;
if(tail <= head)//基准正好是最大元素
continue;
temp = a[tail];//交换
a[tail] = a[head];
a[head] = temp;
tail--;
}
for(int nn = 0; nn < 10; nn++)
cout << a[nn] << " ";
cout <<endl;
quickSort(a, head2, tail - 1);
quickSort(a, tail + 1, tail2);
}
int main()
{
int a[10] = {1, 3, 4 ,2 ,5, 6, 7, 8 , 9, 10};
quickSort(a, 0, 9);
for(int n: a)
cout << n <<endl;
return 0;
}
06-06