Sort by-reverse sort

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.