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