标签:
快速排序
1 package t0107; 2 3 public class PaiXu { 4 5 /** 6 * 快速排序 7 */ 8 public void quickSort(String[] strDate, int left, int right) { 9 String middle,tempDate; 10 int i,j; 11 i=left; 12 j=right; 13 middle=strDate[(i+j)/2]; 14 do{ 15 while(strDate[i].compareTo(middle)<0 && i<right){ 16 i++; //找出左边比中间值大的数 17 } 18 while(strDate[j].compareTo(middle)>0 && j>left){ 19 j--; //找出右边比中间值大的数 20 } 21 if(i<=j){ //将左边大的数和右边小的数进行替换 22 tempDate = strDate[i]; 23 strDate[i]=strDate[j]; 24 strDate[j]=tempDate; 25 i++; 26 j--; 27 } 28 }while(i<=j); //当两者交替时停止 29 30 if(i<right){ 31 quickSort(strDate,i,right); 32 } 33 if(j>left){ 34 quickSort(strDate,left,j); 35 } 36 37 } 38 39 public static void main(String[] args) { 40 String[] strVoid = new String[]{"11","66","22","0","55","22","0","32"}; 41 PaiXu sort = new PaiXu(); 42 sort.quickSort(strVoid,0,strVoid.length-1); 43 for(int i=0; i<strVoid.length;i++){ 44 System.out.println(strVoid[i]+""); 45 } 46 } 47 48 }
标签:
原文地址:http://www.cnblogs.com/cfb513142804/p/4209411.html