1 PackageCom.array;2 3 Public classSort_quick {4 /*5 * Project name: Quick sort;6 * Project requirements: Using the Java array to sort, and the use of fast sorting algorithm;7 * SEVCK;8 */9 Public voidSortintLeftintRightintarray[]) {Ten intL =Left ; One intR =Right ; A intPirot = array[(left + right)/2]; - inttemp = 0; - while(L <r) { the while(Array[l] < Pirot && L >=Left ) -l++; - while(Array[r] > Pirot && r <=Right ) -r--; + if(L >=R) - Break; +temp =Array[l]; AARRAY[L] =Array[r]; atARRAY[R] =temp; - } - - if(L = =r) { -l++; -r--; in } - to if(Left <R) + sort (left, r, array); - if(Right >l) the sort (L, right, array); * } $ Panax Notoginseng Public Static voidMain (string[] args) { - intArr1[] = {7, 3, 2, 9, 15, 1, 14 }; theSort_quick QS =NewSort_quick (); +Qs.sort (0, Arr1.length-1, arr1); A theSystem.out.println ("The current array is:"); + - for(inti = 0; i < arr1.length; i++) { $System.out.print ("" +arr1[i]); $ } - } -}
This need to say, before the quick line has been written wrong, debugging for a long time did not solve, (the results found when not careful-write + +).
See for a long while did not see, arr1.length-1 how can become 7 ... Find chicken Brother asked, instant solved, also was spit Groove code write good rotten. It's not good to see.
But after watching the chicken brother is really self-sigh, good study of his coding style ...
Java sort--[Quick Sort]