问题
Ive been working on selection sort algorithms, just wanted to know the step by step method on working out using the selection sort algorithm.
Just wanted to know if the below is correct
Array: 6, 20, 12, 8
1st phase: n=0 6, 20, 12, 8 (no swap)
2nd phase: n=1 6, 8, 12, 20
3rd phase: n=2 6, 8, 12, 20 (no swap)
回答1:
Yes You are right
arr[] = 6, 20, 12, 8
// Find the minimum element in arr[0...3]
// and place it at beginning
// 6 is minimum and at its place so no swap
6, 20, 12, 8
// Find the minimum element in arr[1...3]
// and place it at beginning of arr[1...3]
// 8 is minimum and so swap it with index at 1
6, 8, 12, 20
// Find the minimum element in arr[2...3]
// and place it at beginning of arr[2...3]
//Every thing is at place no swap
6, 8, 12, 20
来源:https://stackoverflow.com/questions/47310732/selection-sort-algorithm-using-small-array