mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:11:49 +08:00
fix: coding style and file format for chapter 7.
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var s []int
|
||||
|
||||
func main() {
|
||||
s = []int{1, 2, 3}
|
||||
fmt.Println("The length of s before enlarging is:", len(s))
|
||||
fmt.Println(s)
|
||||
s = enlarge(s, 5)
|
||||
fmt.Println("The length of s after enlarging is:", len(s))
|
||||
fmt.Println(s)
|
||||
}
|
||||
|
||||
func enlarge(s []int, factor int) []int {
|
||||
ns := make([]int, len(s) * factor)
|
||||
// fmt.Println("The length of ns is:", len(ns))
|
||||
copy(ns, s)
|
||||
//fmt.Println(ns)
|
||||
s = ns
|
||||
//fmt.Println(s)
|
||||
//fmt.Println("The length of s after enlarging is:", len(s))
|
||||
return s
|
||||
}
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var s []int
|
||||
|
||||
func main() {
|
||||
s = []int{1, 2, 3}
|
||||
fmt.Println("The length of s before enlarging is:", len(s))
|
||||
fmt.Println(s)
|
||||
s = enlarge(s, 5)
|
||||
fmt.Println("The length of s after enlarging is:", len(s))
|
||||
fmt.Println(s)
|
||||
}
|
||||
|
||||
func enlarge(s []int, factor int) []int {
|
||||
ns := make([]int, len(s)*factor)
|
||||
// fmt.Println("The length of ns is:", len(ns))
|
||||
copy(ns, s)
|
||||
//fmt.Println(ns)
|
||||
s = ns
|
||||
//fmt.Println(s)
|
||||
//fmt.Println("The length of s after enlarging is:", len(s))
|
||||
return s
|
||||
}
|
||||
|
Reference in New Issue
Block a user