标签:style swa return turn color stat 排序 快速排序算法 key
1 public class quike { 2 3 public static void QSort(int[] arry,int low,int high) 4 { 5 6 int key; 7 if(low < high) 8 { 9 key = Partition(arry,low,high); 10 QSort(arry,low,key-1); 11 QSort(arry,key+1,high); 12 } 13 14 15 } 16 public static int Partition(int[] arry ,int low ,int high) 17 { 18 int pKey = arry[low]; 19 while(low < high) 20 { 21 while(low < high && arry[high] > pKey) 22 high--; 23 swap(arry,high,low); 24 while(low < high && arry[low] < pKey) 25 low++; 26 swap(arry,high,low); 27 } 28 return low; 29 30 } 31 static void swap(int[] arry,int m,int n) 32 { 33 int temp = arry[m]; 34 arry[m] = arry[n]; 35 arry[n] = temp; 36 } 37 38 public static void main(String[] args) { 39 40 int[] num = {50,10,90,30,70,40,80,60,20}; 41 int low = 0; 42 int high = num.length - 1; 43 QSort(num,low,high); 44 for(int i = 0;i < num.length;i++) 45 { 46 System.out.println(num[i]); 47 } 48 49 } 50 51 }
标签:style swa return turn color stat 排序 快速排序算法 key
原文地址:http://www.cnblogs.com/lyzheng/p/7742632.html