- int hoare_partition(int a[],int low,int high)
- {
- int x=a[low];
- int i=low-1;
- int j=high+1;
- while(1)
- {
- do{j--;}
- while(a[j]>x);
- do{i++;}
- while(a[i]<x);
- if(i<j)
- swap(a[i],a[j]);
- else return j;
- }
- }
- void hoare_quicksort(int a[],int low,int high)
- {
- int q;
- if(low<high)
- {
- q=hoare_partition(a,low,high);
- hoare_quicksort(a,low,q);
- hoare_quicksort(a,q+1,high);
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- int a[9]={45,32,1,5,34,2,4,32,2};
- hoare_quicksort(a,0,8);
- for(int i = 0; i< 9; i++)
- cout << a[i]<<" ";
- return 0;
- }
快速排序其他实现代码
最新推荐文章于 2024-10-22 21:26:19 发布