#自定义排序规则
private void quickSortNums(String []strNums, int l, int r) {
if(l >= r) return;
int low = l, heigh = r;
String strTemp = strNums[l];
while (low < heigh){
while (low < heigh && (strTemp + strNums[heigh]).compareTo(strNums[heigh] + strTemp) <= 0) heigh--;
strNums[low] = strNums[heigh];
while (low < heigh && (strTemp + strNums[low]).compareTo(strNums[low] + strTemp) >= 0) low++;
strNums[heigh] = strNums[low];
}
strNums[low] = strTemp;
quickSortNums(strNums, l, low-1);
quickSortNums(strNums, low+1, r);
}
public void quickSort(int []nums, int l, int r){
if(l >= r) return;
int temp = nums[l];
int low = l, heigh = r;
while(low < heigh){
while (low < heigh && nums[heigh] >= temp) heigh--;
nums[low] = nums[heigh];
while (low < heigh && nums[low] <= temp) low++;
nums[heigh] = nums[low];
}
nums[low] = temp;
quickSort(nums, l, low-1);
quickSort(nums, low+1, r);
}
快速排序步骤,重新学习

本文深入讲解了快速排序算法的实现细节,包括基本的快速排序过程以及针对字符串数组的自定义排序规则实现。通过递归方式调整数组中的元素位置,使得左侧元素小于基准值,右侧元素大于基准值,从而达到高效排序的目的。

被折叠的 条评论
为什么被折叠?



