Examples of Java-based sorting method selection

Source: Internet
Author: User

Select Sort Selection Sort
The basic idea of sorting is to process the sequence of sorted records over n-1 times, and to process over 1st times, L [1 .. n] the smallest one exchanges location with L [1]. For 2nd times .. the smallest person in n] exchanges location with L [2 ,......, the I-th processing is to convert L [I .. the smallest person in n] exchanges location with L [I. In this way, after I times, the positions of the previous I records are arranged in ascending order.
Of course, in actual operations, you can also select the locations of the vertex and its first record from the record to be sorted and sort the records in the ascending order.
The algorithm is as follows:
/**
* Select sorting
* @ Paramsrc the array to be sorted
*/
Void doChooseSort (int [] src)
{
Int len = src. length;
Int temp;
For (int I = 0; I <len; I)
{
Temp = src [I];
Int j;
Int samllestLocation = I; // subscript of the minimum number
For (j = I 1; j <len; j)
{
If (src [j] <temp)
{
Temp = src [j]; // obtain the minimum value
SamllestLocation = j; // retrieve the subscript of the minimum value
}
}
Src [samllestLocation] = src [I];
Src [I] = temp;
PrintResult (I, src );
}
}

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.