Go语言实现冒泡排序


Golang/sort/Go语言/Go语言排序/冒泡排序/Golang实现冒泡排序。

package main

import (
 "fmt"
)

var (
 array = []int{3, 6, 1, 8, 5}
)

func main() {
 for _, v := range sort(array) {
  fmt.Println(v)
 }
}

func sort(array []int) []int {
 for i := 0; i < len(array); i++ {
  for j := 0; j < len(array)-i-1; j++ {
   if array[j] < array[j+1] {
    array[j], array[j+1] = array[j+1], array[j]
   }
  }
 }
 return array
}

Ubuntu 安装Go语言包

《Go语言编程》高清完整版电子书

Go语言并行之美 -- 超越 “Hello World”

我为什么喜欢Go语言

Go语言内存分配器的实现

Go语言的国际化支持(基于gettext-go)

本文永久更新链接地址:

相关内容