import java.util.Scanner; public class QuickSort { public static int[] QuickSort1(int[] a,int low,int high){ low =0; high= a.length-1; int pivot= a[low]; //low+=low; int temp= 0; for(int i=low+1;i<=high&&a[i]>pivot;i++){ for(int j=high;i>=low&&a[j]<pivot;j--){ if(i<j){ temp=a[j]; a[j]=a[i]; a[i]=temp; } if(i>j&&low<j){ temp=a[low]; a[low]=a[j]; a[j]=temp; QuickSort1(a,low,j-1); QuickSort1(a,j+1,high); } } return a; } public static void main(String[] args){ Scanner input= new Scanner(System.in); System.out.println("please enter in ..."); int [] array = new int [10]; for(int i = 0;i<array.length;i++){ array[i]=input.nextInt(); } int []arr2 =new int[10]; int[] a=QuickSort1(array, 0, 20); for(int i = 0;i<array.length;i++){ System.out.println(array[i]); } } }
相关分类