import java.util.Scanner; import java.util.ArrayList; public class Paixu2{ public int[] alist; //快速排序 public static void main(String args[]) { Paixu2 he=new Paixu2(); he.setup(); he.look(); he.go(0,9); he.look(); } public void setup(){ Scanner sc=new Scanner(System.in); alist=new int[10]; for(int i=0;i<10;i++){ alist[i]=sc.nextInt(); } } public void look(){ System.out.println(""); for(int i=0;i<10;i++){ System.out.print(alist[i]); } } public void change(int i,int j){ int tempp; tempp=alist[i]; alist[i]=alist[j]; alist[j]=tempp; } public void go(int i,int j){ if(i>j){ return; } int s=i; int pointi=i; int pointj=j; while(pointj!=pointi){ while(pointj>pointi&&alist[pointj]>=alist[s]){ pointj--; } while(pointj>pointi&&alist[pointi]<=alist[s]){ pointi++; } if(pointj>pointi){change(pointi,pointj);} } change(s,pointj); go(i,pointi-1); go(pointi+1,j); } }
时间: 2024-10-25 21:42:38