日期:2014-05-16 浏览次数:20734 次
#include <stdio.h> void swap(int* a, int* b) { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; } int partition(int* a, int fI, int lI) { int i = fI-1, j = 0; for(j=fI;j<=lI;j++) { if(*(a+j) < *(a+lI)) { i++; if(i != j) swap(a+j, a+i); } } if(i+1 != lI) swap(a+i+1, a+lI); return i+1; } void quickSort(int* a, int fI, int lI) { int partI = 0; if(fI >= lI) return; partI = partition(a, fI, lI); quickSort(a, fI, partI-1); quickSort(a, partI+1, lI); } int main() { int a[10] = {241,325425,56765,234,13,34574,4653,5687689,432552,2789}; int L = sizeof(a) / sizeof(int); int i = 0; quickSort(a, 0, L-1); for(;i<L;i++) printf("%d ", *(a+i)); printf("\n"); return 0; }