使用小数组的选择排序算法
Selection Sort Algorithm using small array
我一直在研究选择排序算法,只是想知道使用选择排序算法进行计算的分步方法。
只是想知道以下是否正确
Array: 6, 20, 12, 8
第一阶段:n=0 6、20、12、8(无交换)
第二阶段:n=1 6, 8, 12, 20
第 3 阶段:n=2 6、8、12、20(无交换)
是的,你是对的
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
我一直在研究选择排序算法,只是想知道使用选择排序算法进行计算的分步方法。
只是想知道以下是否正确
Array: 6, 20, 12, 8
第一阶段:n=0 6、20、12、8(无交换)
第二阶段:n=1 6, 8, 12, 20
第 3 阶段:n=2 6、8、12、20(无交换)
是的,你是对的
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