快速排序Java 实现(自己写的)
public class QSDemo { public static void main(String[] args) { int arr[]={6,2,1,7,3,0,9,8,5,4}; quickSort(arr,0,arr.length-1); for(int i=0;i<arr.length;i++) { System.out.print(arr[i]+" "); } } public static void quickSort(int arr[],int low,int high) { int pos; if(low < high) { pos=function(arr,low,high); quickSort(arr,low,pos-1); quickSort(arr,pos+1,high); } } public static int function(int arr[],int low,int high) { int temp; int val=arr[low]; int index=low; while(low < high) { while(low<high && val<=arr[high]) high--; while(low<high && val>=arr[low]) low++; temp=arr[high]; arr[high]=arr[low]; arr[low]=temp; } temp=arr[low]; arr[low]=val; arr[index]=temp; return low; } }