Classic Sorting Algorithm -- directly select sorting

Source: Internet
Author: User

Straight select sorting is also a simple sorting method. Its basic idea is: the first time from R [0] ~ Select the minimum value in R [n-1] and exchange it with R [0]. The second time is from R [1] ~ Select the minimum value in R [n-1] and exchange it with R [1 ].

Directly selecting sorting is similar to directly inserting sorting. Data is divided into ordered and unordered areas, the difference is that direct playback sorting inserts the first element of the unordered area directly into the ordered area to form a larger ordered area, directly selecting sorting means selecting the smallest element from the unordered area and putting it at the end of the ordered area.

Public class sort {static final int max = 20; public static void main (string [] ARGs) {int [] DATA = new int [Max]; random random = new random (); // generates a random array for (INT I = 0; I <Max; I ++) {data [I] = random. nextint (max * max);} // print the pre-sorted data content system. out. println (arrays. tostring (data); For (INT I = 0; I <max-1; I ++) {int minindx = I; for (Int J = I + 1; j <Max; j ++) {If (data [minindx]> = data [J]) {minindx = J ;}} int temp = data [I]; data [I] = data [minindx]; data [minindx] = temp;} // print the sorted array system. out. println (arrays. tostring (data ));}}

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: 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.