【问题标题】:Selection Sort Algorithm using small array使用小数组的选择排序算法
【发布时间】:2018-04-28 20:59:01
【问题描述】:
我一直在研究选择排序算法,只是想知道使用选择排序算法的逐步方法。
只是想知道以下是否正确
Array: 6, 20, 12, 8
第一阶段:n=0 6、20、12、8(无交换)
第二阶段:n=1 6, 8, 12, 20
第三阶段:n=2 6, 8, 12, 20(无交换)
【问题讨论】:
标签:
java
arrays
algorithm
selection
【解决方案1】:
是的,你是对的
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