1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include<cstdio> #include<ctime> #include<cstdlib> inline void (int &a, int &b) { if(a!=b) { a^=b; b^=a; a^=b; } } int Partition(int *A,int front,int end) { int key = A[end]; int i = front - 1; for(int current = front;current < end;++current) { if(A[current]<=key) Swap(A[++i],A[current]); } Swap(A[++i],A[end]); return i; } void QuickSort (int *A,int front,int end) { if(front < end) { int midPosition = Partition(A,front,end); QuickSort(A,front,midPosition-1); QuickSort(A,midPosition+1,end); } }
|
近期评论