快速排序

int partition(int*a, int left, int right){
int low;
if (left < right){

low = left;
int high = right;
int value = a[left];

while (low < high){

while (low < high&&a[high] >= value) high--;
a[low] = a[high];

while (low < high&&a[low] <= value) low++;
a[high] = a[low];

}

a[low] = value;
}
return low;
}


void quicksort(int* a, int left, int right){
if (left < right){
int mid = partition(a, left, right);

quicksort(a, left, mid - 1);
quicksort(a, mid + 1, right);
}

}

 

left<right不能加等于。

posted @ 2019-10-10 11:56  一日一更  阅读(127)  评论(0编辑  收藏  举报