//// main.swift// //// Created by LongMa on 2020/7/4.// copyright © 2020 . All rights reserved.//import Foundationprint("Hello,World!")func kp(arr : [Int]) -> Array<Int>{ var a = arr let len = arr.count var indexOfMinNum,temp : Int for i in 0..<(len - 1) {//eg:3个数,应循环2次 indexOfMinNum = i //无序部分,查找最小值,记录下标。 for j in (i+1)..<(len){//eg:3个数,最大小标为2。 if a[j] < a[indexOfMinNum] { indexOfMinNum = j } } //交换无序部分0位值和最小值 if i != indexOfMinNum { temp = a[i] a[i] = a[indexOfMinNum] a[indexOfMinNum] = temp } } return a}let lArr = [22,6,4,5,10,11,2,1,0]let lA = kp(arr: lArr)print(lA)let lArr1 = [23,8,9,3,1]let lA1 = kp(arr: lArr1)print(lA1)
log:
Hello,World![0,22][0,23]Program ended with exit code: 0
总结 以上是内存溢出为你收集整理的排序之选择排序实现(swift)全部内容,希望文章能够帮你解决排序之选择排序实现(swift)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)