快速排序例程
#include <iostream>
using namespace std;
void QuickSort(int a[], int low, int high)
{
if(low>=high)
return;
int i=low;
int j=high;
int key=a[i];
while(i<j)
{
while((i<j)&(key<=a[j]))
j--;
a[i]=a[j];
while((i<j)&(key>=a[i]))
i++;
a[j]=a[i];
}
a[j]=key;
QuickSort(a,low,j-1);
QuickSort(a,j+1,high);
}
int main()
{
int a[] = {57, 68, 59, 52, 72, 28, 96, 33, 24};
int len=sizeof(a)/sizeof(a[0]);
QuickSort(a, 0, len-1);
for(int i = 0; i < len; i++)
{
cout << a[i] << " ";
}
system("pause");
return 0;
}/*参考数据结构p274(清华大学出版社,严蔚敏)*/