Motioned:
Even:
Initial array Resource "10 20 30 40 50 60"
First trip sort after 60 "20 30 40 50" 10
Second trip sorted after 60 50 "30 40" 20 10
Third trip sort after 60 50 40 30 20 10
Odd:
Initial array Resource "10 20 30 23 40 50 60"
First trip sort after 60 "20 30 23 40 50" 10
Second trip sorted after 60 50 "30 23 40" 20 10
Third trip sort after 60 50 40 23 30 20 10
Instance:
1 /**2 * Reverse Sort algorithm instance3 * 4 * @authorLi Zhong Wei5 */6 Public classReversesort {7 Public Static voidMain (string[] args) {8 //Create an array9 int[] Array = {10, 20, 30, 40, 50, 60 };Ten //create an object that reverses the sort class OneReversesort Sorter =NewReversesort (); A //The method that invokes the sort object reverses the array - Sorter.sort (array); - } the - /** - * Direct selection of the sorting method - * + * @paramArray - * The array to sort + */ A Public voidSortint[] Array) { atSystem.out.println ("Array Original content:"); -Showarray (array);//the array value before the output is sorted - inttemp; - intLen =Array.Length; - for(inti = 0; i < LEN/2; i++) { -temp =Array[i]; inArray[i] = array[len-1-i]; -Array[len-1-I] =temp; to } +System.out.println ("After array inversion content:"); -Showarray (array);//output sorted array values the } * $ /**Panax Notoginseng * Show all elements of an array - * the * @paramArray + * The array to display A */ the Public voidShowarray (int[] Array) { + for(intI:array) {//The foreach format iterates through the array -System.out.print ("\ t" + i);//output each array element value $ } $ System.out.println (); - } -}
Sort by-reverse sort