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 ));}}