java的快速排序出问题了,但是不知道那错了

import java.util.Scanner;

public class quickSort2 {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.print("请输入要创建的数列个数:");
int n = sc.nextInt();
int[] list = new int[n];
if (sc.hasNext()) {
for(int i=0; i list[i] = sc.nextInt();
}
}
quick(list);
for(int i=0;i System.out.println(list[i]);
}
/**
Scanner sc = new Scanner(System.in);
String inputString = sc.next().toString();
String stringArray[]=inputString.split(",");
int list[] = new int[stringArray.length];
if (sc.hasNext()) {
for(int i=0;i list[i]=Integer.parseInt(stringArray[i]);
}
quick(list);
for(int i=0;i System.out.println(list[i]);
}
}
*/
}
//划分
public static int getMiddle(int[] list,int low,int high){
while(low while(low=list[low]){
high--;
}
int temp = list[low];list[low]=list[high];list[high] = temp;
low++;
while(low low++;
}
int temp1 = list[low];list[low]=list[high];list[high] = temp1;
high--;
}
return low;
}
//排序
public static void Sort(int[] list,int low,int high){
if(low int middle=getMiddle(list,low,high);
Sort(list,low,middle-1);
Sort(list,middle+1,high);
}
}
public static void quick(int[] list){
if(list.length>0){
Sort(list,0,list.length-1);
}
}
}

1个回答

已解决了,自己粗心,没有严格划分区间。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!