选择排序 selection Sort
概述
按指定的规则选出来某个元素,再依规定交换位置.可以不断缩小范围将最小值放在前方。
图解过程
// Find the minimum element in arr[0…4]
// and place it at beginning
11 25 12 22 64
// Find the minimum element in arr[1…4]
// and place it at beginning of arr[1…4]
11 12 25 22 64
// Find the minimum element in arr[2…4]
// and place it at beginning of arr[2…4]
11 12 22 25 64
// Find the minimum element in arr[3…4]
// and place it at beginning of arr[3…4]
11 12 22 25 64
造轮子
1 | public void sort(int arr[]) |
选择排序 selection Sort