gpt4 book ai didi

java - 使用小数组的选择排序算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:15:29 25 4
gpt4 key购买 nike

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

只是想知道以下是否正确

Array: 6, 20, 12, 8

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

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

第三阶段: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

关于java - 使用小数组的选择排序算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47310732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com