废话不多说,上代码:
void quicksort(int x[], int lo, int hi){ int i = lo, j = hi; int pivot = x[(lo + hi) >> 1]; while(i <= j){ while(x[i] < pivot) i++; while(x[j] > pivot) j--; if(i <= j){ swap(x[i], x[j]); i++; j--; } } if(lo < j) quicksort(lo, j); if(i < hi) quicksort(i, hi); }
Reference: here
时间: 2024-10-10 02:43:54