How "Java SE" uses Java to directly select sort

Source: Internet
Author: User

Absrtact: The direct selection sort belongs to the selection sort, but its sorting algorithm is faster than the bubble sort, because its algorithm is relatively simple, so it is more suitable for beginners to learn mastery.

    1. Suitable crowd: There is a certain Java SE Foundation, understand the Java data type, array definition, initialization and common array methods, as well as the Java loop operation.

    2. Pre-Preparation: It is best to have a development tool such as: Eclipse or MyEclipse can, of course, you use a DOS system to compile and run, but the bug will be a bit troublesome.

    3. Sorting principle: The principle of direct selection is to compare the specified sort position with other array elements, if the value of the position is swapped if the condition is met, note that the bubble sort is not exchanged, instead of exchanging adjacent elements, instead of exchanging the elements that satisfy the condition with the specified sort position.
    4. Compare bubble Sort: The direct selection sort is much smaller than the bubble sort, so the speed is a bit faster.
    5. Advantages and disadvantages of direct ordering: The operation speed is faster than bubble sort, but because there is an interchange between the nonadjacent elements in the direct selection sort, the direct selection of the sorting is an unstable sort method.
    6. Algorithm implementation:
1  PackageLiuenci.cn.package_3;2 3  Public classSelectsort {4 5     /**6 * Direct Select sort7      */8      Public Static voidMain (string[] args) {9         //TODO auto-generated Method StubTen         //create an array of random order One         int[] array={2,55,62,44,25,16}; A         //creating objects that are sorted directly -Selectsort sorter=NewSelectsort (); -         //call the direct selection algorithm to sort the array the Sorter.sort (array); -     } -      Public voidSortint[] Array) { -         intindex; +          for(inti=1;i<array.length;i++){ -Index=0; +              for(intj=1;j<=array.length-i;j++){ A                 if(array[j]>Array[index]) { atindex=J; -                 } -                 //swap two numbers on position array.length-i and index (maximum) -                 inttemp=array[array.length-i]; -array[array.length-i]=Array[index]; -array[index]=temp; in             } -              to         } + Showarray (array); -     } the      Public voidShowarray (int[] Array) { *         //TODO auto-generated Method Stub $          for(inti=0;i<array.length;i++){Panax Notoginseng             intnum=Array[i]; -System.out.print (num+ ""); the         } + System.out.println (); A     } the  +}

How "Java SE" uses Java to directly select 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.