1. Direct Select sort:
First:
To tell the truth, the direct selection of the most similar to the sort of human instinct, such as the size of toys to the three-year-old child on the size of a sequence,
The child will first find the smallest of the toys in the first place, then find the second one, and so on.
The first step: we take 80 as a reference (base), find a minimum number of 20 after 80, and then swap 80 with 20.
Step two: The first digit is already the smallest number, and then we push further after 30 to find a minimum number, find themselves the smallest without swapping.
Step Three: ...
The program source code is:
1 Packagecom.swust. Select sort;2 Importcom.swust.utils.ArrayUtils;3 4 Public classExample1 {5 Public Static voidMain (string[] args) {6 int[] arr = Arrayutils.createarray (10);7 sort (arr);8 Arrayutils.showarray (arr);9 }Ten Private Static voidSortint[] arr) { One //number of times to traverse A for(inti=0;i<arr.length-1;i++){ - //first assume that the position of the smallest element is I - intsmall =i; the for(intj=i;j<arr.length;j++){ - //find the true minimum element, and replace the subscript that assumes the smallest element with the true minimum element - if(arr[small]>Arr[j]) { -Small=J; + } - } + //swap the true minimum element with the assumed minimum element position A inttemp =Arr[small]; atArr[small] =Arr[i]; -arr[i]=temp; - } - } -}
Selection and sequencing of data structure learning