1 Star 0 Fork 0

decore/gostruct

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bubblesort.go 711 Bytes
一键复制 编辑 原始数据 按行查看 历史
waytai 提交于 2018-05-31 20:48 . bubblesort
package main
import (
"fmt"
)
type SortInterface interface {
sort()
}
type Sortor struct {
name string
}
func main() {
arry := []int{6, 1, 3, 5, 8, 4, 2, 0, 9, 7}
learnsort := Sortor{name: "冒泡排序--从小到大--稳定--n*n---"}
learnsort.sort(arry)
fmt.Println(learnsort.name, arry)
}
func (sorter Sortor) sort(arry []int) {
done := true
arrylength := len(arry)
for i := 0; i < arrylength && done; i++ {
done = false
for j := 0; j < arrylength-i-1; j++ {
done = true
if arry[j] > arry[j+1] {
t := arry[j]
arry[j] = arry[j+1]
arry[j+1] = t
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/waytai/gostruct.git
git@gitee.com:waytai/gostruct.git
waytai
gostruct
gostruct
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385