Selection Sort Algorithm using small array

孤者浪人 提交于 2020-01-03 03:22:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!