Reverse sort of Java

Source: Internet
Author: User
Tags mail exchange

As the name implies, reversing the order is to reorder the contents of the original array in the reverse sequence. The inverse sorting algorithm is often used in our program development. The basic idea of reverse ordering is simply to swap the last element of the array with the first one, the second and the second to swap, and so on, until all the elements are reversed. Let's look at an example.

1 /**2 * Reverse Sort algorithm instance3  */4  Public classReversesort {5      Public Static voidMain (string[] args) {6         //Create an array7         int[] Array = {Ten, -, -, +, -, -, - };8         //create an object that reverses the sort class9Reversesort Sorter =NewReversesort ();Ten         //The method that invokes the sort object reverses the array One Sorter.sort (array); A     } -      -     /** the * Direct selection of the sorting method -      *  - * The array to sort -      */ +      Public voidSortint[] Array) { -System. out. println ("The original contents of the array:"); +Showarray (array);//the array value before the output is sorted A         inttemp; at         intLen =Array.Length; -          for(inti =0; I < Len/2; i++) { -temp =Array[i]; -Array[i] = Array[len-1-i]; -Array[len-1-I] =temp; -         } inSystem. out. println ("The contents of the array after inversion:"); -Showarray (array);//output sorted array values to     } +      -     /** the * Show all elements of an array *      *  $ * @param arrayPanax Notoginseng * The array to display -      */ the      Public voidShowarray (int[] Array) { +          for(intI:array) {//The foreach format iterates through the array ASystem. out. Print ("\ t"+ i);//output each array element value the         } +System. out. println (); -     } $}

Conv New, published in the blog Park

Reprint please indicate the source, welcome mail exchange:[email protected]

Reverse sort of Java

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.