Select sort (Selection sort)
Select Sort:
The smallest (or largest) element is selected for each data element that has never been sorted, stored at the beginning of the sequence, and then the smallest (or largest) of the remaining unsorted elements is placed at the end of the sorted sequence until all the data elements to be sorted are exhausted.
Select Sort is an unstable sort method (for example, sequence [5, 5, 3] swaps the first [5] with [3] for the first time, causing the first 5 to move back to the second 5).
Algorithm introduction (subsequent additions)
Performance Introduction (Subsequent additions)
Introduction to Suboptimal (Follow-up supplement)
Code presentation (for example from small to large)
public class SelectSort { public static void main(String[] args){ int[] arr = {1,22,32,2,5,75,46,37,23,99}; int[] arrSort = selectSort(arr); for(int i = 0; i < arrSort.length; i++){ System.out.println(arr[i]); } } //选择排序 public static int[] selectSort(int[] arr){ int minIndex = 0; for(int i = 0; i < arr.length-1; i++){ minIndex = i;//用来动态记录较小数字的下标 for(int j = i+1; j < arr.length; j++){ if(arr[minIndex] > arr[j]){ minIndex = j; } } if(minIndex != i){ arr[minIndex] = arr[minIndex] + arr[i]; arr[i] = arr[minIndex] - arr[i]; arr[minIndex] = arr[minIndex] - arr[i]; } } return arr; }}
The choice of Jave basis