package main
import "fmt"
func main(){
a:=[...]int {40,30,10,9,8,100,200,90}
fmt.Println(a)
//从大到小排序
num:=len(a)
for i:=0;i
for j:=i+1;j
if a[i]>a[j]{
a[i],a[j]=a[j],a[i]
}
}
}
fmt.Println(a)
}
输出:
[40 30 10 9 8 100 200 90]
[8 9 10 30 40 90 100 200]
package main
import "fmt"
func main(){
a:=[...]int {40,30,10,9,8,100,200,90}
fmt.Println(a)
//从大到小排序
num:=len(a)
for i:=0;i
for j:=i+1;j
if a[i]>a[j]{
a[i],a[j]=a[j],a[i]
}
}
}
fmt.Println(a)
}
输出:
[40 30 10 9 8 100 200 90]
[8 9 10 30 40 90 100 200]