Package com. arithmetic; import java. util. arrays; // selection sort is a simple and intuitive sorting method.Algorithm. // Its working principle is as follows. First, find the smallest (large) element in the unordered sequence, store it to the starting position of the sorting sequence, // then, continue searching for the smallest (large) element from the remaining unordered elements, put it at the end of the sorted sequence. // And so on until all elements are sorted. Public class test_wzs010 {public static void main (string [] ARGs) {int [] intarray = {10, 3, 5, 7, 9, 1, 4, 2, 6, 8}; choosesort (intarray); system. out. println ("\ n after sorting:" + arrays. tostring (intarray);}/*** select sort ** @ Param intarray * array to be sorted */static void choosesort (INT [] intarray) {int length = intarray. length; int temp; // used to store the smallest int minimumindex; For (INT I = 0; I <length; I ++) {temp = intarray [I]; minimumindex = I; for (Int J = I + 1; j <length; j ++) {If (intarray [J] <temp) {temp = intarray [J]; minimumindex = J ;}} intarray [minimumindex] = intarray [I]; intarray [I] = temp; system. out. println ("Number" + (I + 1) + "Times:" + arrays. tostring (intarray ));}}}
Output result:
1st sorting: [1, 3, 5, 7, 9, 10, 4, 2, 6, 8] 2nd sorting: [1, 2, 5, 7, 9, 10, 4, 3, 6, 8] 3rd sorting: [1, 2, 3, 7, 9, 10, 4, 5, 6, 8] 4th sorting: [1, 2, 3, 4, 9, 10, 7, 5, 6, 8] 5th sorting: [1, 2, 3, 4, 5, 10, 7, 9, 6, 8] 6th sorting: [1, 2, 3, 4, 5, 6, 7, 9, 10, 8] 7th sorting: [1, 2, 3, 4, 5, 6, 7, 9, 10, 8] 8th sorting: [1, 2, 3, 4, 5, 6, 7, 8, 10, 9] 9th sorting: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 10th sorting: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] After sorting: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]