1 Package com.yzy.test;2 3 Public classTest {4 5 /**6 * @param args7 */8 Public Static voidMain (string[] args) {9 int[] Array = { +, -, +,6565,3424, A,6523,345 };TenArraySort (Array,0, Array.Length-1); One for(intI:array) { ASystem. out. print (i +" "); - } - } the - //Quick Sort Method - Private Static voidArraySort (int[] Array,intLowindex,intHighindex) { - intLow =Lowindex; + intHigh =Highindex; - intmid; + if(Lowindex <Highindex) { A while(Low <=High ) { atMid = array[(Lowindex + highindex)/2]; - while(Low < Highindex) && (Array[low] <mid)) { -++Low ; - } - while((High > Lowindex) && (Array[high] >mid)) { ---High ; in } - if(Low <=High ) { to Wrap (array, low, high); +++Low ; ---High ; the } * } $ if(Low <Highindex) {Panax Notoginseng ArraySort (array, low, highindex); - } the if(High >Lowindex) { + arraysort (array, lowindex, high); A } the } + - } $ $ //Exchanging array elements - Private Static voidWrapint[] Array,intLowintHigh ) { - //TODO auto-generated Method Stub the inttemp =Array[low]; -Array[low] =Array[high];WuyiArray[high] =temp; the } -}
Technical points: quick Sorting is an improvement on the sorting of bubbles, which is relatively fast. The basic idea is to divide the sorted data into two separate parts, one by one, and all of the data in part is smaller than the rest of the data, and then the two parts of the data are sorted quickly by this method. The entire sorting process can be done recursively, so that the entire data becomes an ordered sequence.
Java sorting an array by using quick sort