版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010841296/article/details/77418274
public static void main(String[] args) {
int[] param = new int[]{1,-1,3,7,-2,8};
int[] res = sort(param,0,param.length-1);
for (int re : res) {
System.out.print(re);
}
}
private static int[] sort(int[] nums,int left,int right) {
if(left >= right){
return nums;
}
int l = left;int r = right;
int orign = nums[l];
while(l<r){
while(l<r&&orign<nums[r]){
r--;
}
if(l<r){
nums[l++] = nums[r];
}
while(l<r&& orign>nums[l]){
l++;
}
if(l<r){
nums[r--] = nums[l];
}
}
nums[l] = orign;
sort(nums,left,l-1);
sort(nums,l+1,right);
return nums;
}