快速排序C++
快速排序C++
int parition(vector<int>& nums, int low, int high){
int pivot = nums[low];
while(low < high){
while(low < high && nums[high] >= pivot){
high--;
}
nums[low] = nums[high];
while(low < high && nums[low] <= pivot){
low++;
}
nums[high] = nums[low];
}
nums[low] = pivot;
return low;
}
void quickSort(vector<int>& nums, int low, int high){
if(low < high){
int pivot = parition(nums, low, high);
quickSort(nums, low, pivot - 1);
quickSort(nums, pivot + 1, high);
}
}
算法 文章被收录于专栏
JavaScript算法