Three major sorts of Java

Source: Internet
Author: User

Package Test3;public class sort{/** * Bubble sort * @param array */public void Bubblesort (int[] array) {for (int i = 1; i < arr Ay.length; i++) {for (int j = 0; J < Array.length-i; J + +) {if (Array[j] > array[j + 1])//Determine the size of the adjacent two elements {int c = array[j];//Save the first element's Value Array[j] = array[j + 1];//give the second value to the first array[j + 1] = c;//give the first value to the second}}}showarray (array);} /** * Select sort * @param array */public void Selectsort (int[] array) {int index;for (int i = 1; i < Array.Length; i++) {Index = 0;for (int j = 1; J <= Array.length-i; j + +) {if (Array[j] > Array[index])//Find maximum value {index = j;}}           int c = Array[array.length-i];     Element last value array[array.length-i] = Array[index]; Put the selected maximum or minimum value on the last value array[index] = c;//The last value to be selected to the maximum or minimum value}showarray (array);} /** * Reverse Sort * @param array */public void Reversesort (int[] array) {SYSTEM.OUT.PRINTLN ("array original value"); Showarray (array); int C;for ( int i = 0; i < ARRAY.LENGTH/2; i++) {//loop array half c = array[i];//Gets the first value, puts the temporary variable array[i] = array[array.length-1-i];//puts the last value on the first value Array[aRray.length-1-I] = c;//Place the first value on the last value on the value}system.out.println ("array reversal value"); Showarray (arrays);} private void Showarray (int[] array) {for (int is:array) {System.out.print ("\ t" +is);} System.out.println ();}}

  

Three major sorts 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.