我一直在研究选择排序算法,只是想知道使用选择排序算法的逐步方法。
只是想知道以下是否正确
Array: 6, 20, 12, 8
第一阶段:n = 0 6,20,12,8(无交换)
第二阶段:n = 1 6,8,12,20
第3阶段:n = 2 6,8,12,20(无交换)
答案 0 :(得分:0)
是的你是对的
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