class Solution {
public:
//不稳定的高效排序 -- 快速排序
void quickSort(vector<int> & v, int first , int last){
if (first < last){
int ans = v[first];
int x = first;
int y = last;
while (x < y){
while (x < y && v[y] > ans){
y--;
}
if (x < y){// x <y 这个判断条件任何时候都不可以少
v[x++] = v[y];
}
while (x < y && v[x] < ans){
x++;
}
if (x < y){
v[y--] = v[x];
}
}
v[x] = ans;
quickSort(v, first, x - 1);
quickSort(v, x + 1, last);
}
}
};
快速排序
最新推荐文章于 2021-11-19 16:57:43 发布