added some sorting to the slices example
This commit is contained in:
parent
02944ee3dc
commit
05649fb4d2
28
slices/go.go
28
slices/go.go
|
@ -1,21 +1,25 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "sort"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
p := []int{2, 3, 5, 7, 11, 13}
|
p := []int{2, 3, 13, 7, 5, 11}
|
||||||
fmt.Println("p ==", p)
|
fmt.Println("p ==", p)
|
||||||
|
sort.Ints(p)
|
||||||
|
fmt.Printf("%T p: %v\n", p, p)
|
||||||
|
|
||||||
for i := 0; i < len(p); i++ {
|
for i := 0; i < len(p); i++ {
|
||||||
fmt.Printf("p[%d] == %d\n", i, p[i])
|
fmt.Printf("p[%d] == %d\n", i, p[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
// slice index notation: (python)
|
// slice index notation: (python)
|
||||||
fmt.Println("p[1:4] == ", p[1:4])
|
fmt.Println("p[1:4] == ", p[1:4])
|
||||||
fmt.Println("p[:3] == ", p[:3])
|
fmt.Println("p[:3] == ", p[:3])
|
||||||
fmt.Println("p[4:] == ", p[4:])
|
fmt.Println("p[4:] == ", p[4:])
|
||||||
|
|
||||||
|
v := make([]string, 0)
|
||||||
|
v = append(v, "hello", "world")
|
||||||
|
fmt.Printf("%v\n", v)
|
||||||
|
|
||||||
v := make([]string, 0)
|
|
||||||
v = append(v, "hello", "world")
|
|
||||||
fmt.Printf("%v\n", v)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue