golang之冒泡排序

 1 package main
 2 
 3 import "fmt"
 4 
 5 func sort(array []int) {
 6     length := len(array)
 7     for i := 0; i < length-1; i++ {
 8         for j := i + 1; j < length; j++ {
 9             if array[i] > array[j] {
10                 array[i], array[j] = array[j], array[i]
11             }
12         }
13     }
14 }
15 
16 func main() {
17     array := []int{9, 2, 10, 1, 5, 7, 3, 4, 8}
18     sort(array)
19     fmt.Println(array)
20 }

 

posted @ 2020-06-12 14:58  卓扬  阅读(180)  评论(0编辑  收藏  举报