#include "stdio.h"
#include "stdlib.h"
#include "string.h"
void quick_sort(int* buf, int len) {
int base = buf[0];
int* free_space = buf;
int* start = buf+1;
int* end = buf+len-1;
int bigger_num = 0;
int less_num = 0;
bool compare_from_end = true;
for(int i=0; i if(compare_from_end) {
if(*end < base) {
*free_space = *end;
free_space = end;
compare_from_end = false;
less_num++;
} else {
bigger_num++;
}
end--;
} else {
if(*start > base) {
*free_space = *start;
free_space = start;
compare_from_end = true;
bigger_num++;
} else {
less_num++;
}
start++;
}
}
*free_space = base;
if(less_num > 1)quick_sort(buf, less_num);
if(bigger_num > 1)quick_sort(buf+less_num+1, bigger_num);
}
int main() {
int arr[100000];
int len = sizeof(arr)/4;
quick_sort(arr, len);
for(int i=0; i printf("%d\t", arr[i]);
}
printf("\n");
getchar();
return 0;
}
阅读(840) | 评论(0) | 转发(0) |