Java structure and algorithm selection sorting

Source: Internet
Author: User

First, Java structure and algorithm selection sort

What's the matter? Select Sort: A small and medium value is selected from a set of unordered data, and the value is exchanged with the leftmost value of the unordered area.

Simple explanation: Suppose there is such a set of data 12,4,23,5, find the minimum value 4 on the far right, and then find 5 to put in the back of 4, repeat the operation.

Select the Sort reference code:

 Public classChoosesort {int[] Array =NULL; @Test Public voidTestpopsort () {array=New int[5]; array[0] = 45; array[1] = 22; array[2] = 33; array[3] = 43; array[4] = 34; intNelmes =Array.Length; inti;  for(intn = 0; n < nElmes-1; n++) {            intMin =N;  for(i = n + 1; i < nelmes; i++) {                if(Array[min] >Array[i]) {min=i;        }} swap (n, min);    } System.out.println (arrays.tostring (array)); }    Private voidSwapintOneintBoth ) {Integer temp=Array[one]; Array[one]=Array[two]; Array[two]=temp; }}

Java structure and algorithm selection sorting

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.