#include <iostream>
using namespace std;
int swap(int& a, int& b);
int sort(int* a, int low, int hight);
int show(int* a, int len);
int main() {
int a[10] = {1,2,3,2,53,123,64,13,431234,31312};
show(a, 10);
cout << "---------------------------------------------------------------------" << endl;
sort(a, 0, 9);
show(a, 10);
cout << "--------------------------------------------------------------------" << endl;
show(a, 10);
return 0;
}
int swap(int& a, int& b) {
int temp = a;
a = b;
b = temp;
return 0;
}
int sort(int* a, int low, int hight){
int temp = a[low];
int left = low;
int right = hight;
if(left > right) {
return 0;
}
while (left != right) {
while (a[right] >= temp && left < right) {
right --;
}
while(a[left] <= temp && left < right) {
left ++;
}
if (left < right) {
swap(a[left], a[right]);
}
}
a[low] = a[left];
a[left] = temp;
sort(a, low, left - 1);
sort(a, left + 1, hight);
return 0;
}
int show(int* a, int len) {
for (int i = 0; i < len; i++) {
cout << a[i] << " ";
}
putchar('\n');
return 0;
}
#顺序不可换 本人亲测