给定一个有9个整数(1,6,2,3,9,4,5,7,8)的数组,输出排序后的数组的值。 (选择排序)(每空2分,共10分) object paixu{ def main(args: Array[String]): Unit = { val array = Array(1,6,2,3,9,4,5,7,8) for (i<- 0 until array.length-1){ var minlndex=(1) for (j<- i until (2)){ if (array(minlndex)>array(j+1)){ minlndex =(3)0 } val tmp:lnt = (4) array(i) = array(minlndex) array(minlndex) =(5) var k=0 for(k <- 0 to array.length - 1){ print(array(k)+" ")}
时间: 2023-10-01 07:03:24 浏览: 87
3_判断素数_yes_
object paixu{
def main(args: Array[String]): Unit = {
val array = Array(1,6,2,3,9,4,5,7,8)
for (i <- 0 until array.length-1){
var minIndex = i
for (j <- i until array.length){
if (array(minIndex) > array(j)){
minIndex = j
}
}
val tmp = array(i)
array(i) = array(minIndex)
array(minIndex) = tmp
}
for(k <- 0 to array.length - 1){
print(array(k)+" ")
}
}
}
输出结果为:1 2 3 4 5 6 7 8 9
阅读全文