使用小数组的选择排序算法 [英] Selection Sort Algorithm using small array

查看:163
本文介绍了使用小数组的选择排序算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究选择排序算法,只是想知道使用选择排序算法的逐步方法。

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

第1阶段:n = 0 6,20,12,8(没有交换)

1st phase: n=0 6, 20, 12, 8 (no swap)

第二阶段:n = 1 6,8,12,20

2nd phase: n=1 6, 8, 12, 20

第3阶段:n = 2 6,8,12,20(无交换)

3rd phase: n=2 6, 8, 12, 20 (no swap)

推荐答案

是的你是对的

  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

这篇关于使用小数组的选择排序算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆