红色为被选中的pt
1个pt排好序后就把该pt标红
private Integer selPt(List<Integer> list, int left, int right) {
if (left >= right) {
return left;
}
int ptVal = list.get(left);
int l =left, r=right;
while (l < r) {
while (l < r && list.get(r) > ptVal) {
r--;
}
while (l < r && list.get(l) <= ptVal) {
l++;
}
if (l < r) {
int t = list.get(l);
list.set(l, list.get(r));
list.set(r, t);
}
}
list.set(left, list.get(l));
list.set(l, ptVal);
return l;
}
public void quickSort(List<Integer> list, int l, int r) {
if (l >= r) {
return;
}
int pt = selPt(list, l, r);
quickSort(list, l, pt-1);
quickSort(list, pt+1, r);
}
参照 冒泡排序可视化
要想实现结果图中代码 需要稍加改造 选出来pt后指定该pt位置的颜色