#include <iostream>
#include <array>
using namespace std;
void qucikSort(int * a,int n)
{
int i , j;
int val = a[n/2];
if (n < 2) return;
cout << "start:";
for ( j = 0; j < n; j++){
cout << a[j] <<" ";
}
cout << " " ;
for ( i = 0, j = n - 1; ; i++,j--){
while (a[i] < val) i++ ;
while (a[j] > val) j--;
if (i >= j) break;
int temp = a[i]; a[i] = a[j]; a[j] = temp;
}
cout << "end:";
for ( j = 0; j < n; j++){
cout << a[j] <<" ";
}
cout << endl ;
qucikSort (a,i);
qucikSort (a + i,n-i);
}
int main()
{
int a[10] = {1,2,5,9,8,7,6,4,3,0};
int n = sizeof(a)/sizeof(a[0]);
cout << "start: ";
for (int i = 0; i < 10; i++)
{
cout << a[i] << " " ;
}
cout << endl;
qucikSort (a,n);
cout << "end: ";
for (int i = 0; i < 10; i++)
{
cout << a[i] << " " ;
}
cout << endl;
system ("pause");
return 0 ;
}
快排 - 打印logo
最新推荐文章于 2024-09-02 23:09:18 发布