45 Star 130 Fork 53

Apocalypse / c2go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
16.go 466 Bytes
一键复制 编辑 原始数据 按行查看 历史
ZenQy 提交于 2015-03-29 18:12 . last push
//有一个已经排好序的数组。现输入一个数,要求按原来的规律将它插入数
//组中。
//简化了一下,仅保留功能。。。
package main
import (
"fmt"
)
const N = 5
func main() {
s1 := make([]int, 10)
s2 := []int{0, 1, 2, 3, 4, 6, 7, 8, 9}
copy(s1, s2)
for i := 8; i >= 0; i-- {
if N <= s1[i] && N >= s1[i-1] {
s1[i+1], s1[i] = s1[i], N
break //插入后退出
} else {
s1[i+1] = s1[i]
}
}
fmt.Println(s1)
}
Go
1
https://gitee.com/justin.qin/c2go.git
git@gitee.com:justin.qin/c2go.git
justin.qin
c2go
c2go
master

搜索帮助