thought

Simple selection sort is the most simple and intuitive algorithm, the basic idea for each trip from the data elements to be sorted to select the smallest (or the largest) one element as the first element, until all the elements are finished, simple selection sort is not stable sort.

The illustration

Time complexity

O (N squared)

code

` public void selectionSort(int[] arr){ if (arr ==null || arr.length<2){ return; } for (int i=0; i<arr.length; i++){ int minIndex = i; for (int j=i+1; j<arr.length; j++){ minIndex =arr[j]<arr[minIndex]? j:minIndex; } swap(arr,i,minIndex); } } public void swap(int[] arr,int i,int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } `Copy the code