近几日发现自己连快速排序都忘记了,特此记录一下,加深记忆
备注就没有很简单,就是为了温习温习
import java.util.Arrays;
public class QuietSort {
private static void quietSort(int[] nums, int low, int high){
int start = low;
int end = high;
int key = nums[start];
while(end>start){
while(end>start && nums[end]>=key)
end--;
if(nums[end]<=key){
int temp = nums[end];
nums[end] = nums[start];
nums[start] = temp;
}
while(end>start&&nums[start]<=key)
start++;
if(nums[start]>=key){
int temp = nums[start];
nums[start] = nums[end];
nums[end] = temp;
}
}
if(start>low) quietSort(nums,low,start-1);
if(end<high) quietSort(nums,end+1,high);
}
public static void main(String[] args) {
int[] nums = {3,7,4,6,2,5};
quietSort(nums,0,5);
System.out.println(Arrays.toString(nums));
}
}
原文:https://www.cnblogs.com/Fsight/p/12443875.html