1 Star 0 Fork 52

Palmworld/c2go

forked from Apocalypse/c2go 
Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
16.go 466 Bytes
Copy Edit Raw Blame History
ZenQy authored 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)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/imwinjune/c2go.git
git@gitee.com:imwinjune/c2go.git
imwinjune
c2go
c2go
master

Search

0d507c66 1850385 C8b1a773 1850385