1
0
Fork 0

added some sorting to the slices example

This commit is contained in:
Stephen M. McQuay 2012-08-02 14:39:13 -06:00
parent 02944ee3dc
commit 05649fb4d2
1 changed files with 16 additions and 12 deletions

View File

@ -1,21 +1,25 @@
package main
import "fmt"
import "sort"
func main() {
p := []int{2, 3, 5, 7, 11, 13}
fmt.Println("p ==", p)
p := []int{2, 3, 13, 7, 5, 11}
fmt.Println("p ==", p)
sort.Ints(p)
fmt.Printf("%T p: %v\n", p, p)
for i := 0; i < len(p); i++ {
fmt.Printf("p[%d] == %d\n", i, p[i])
}
for i := 0; i < len(p); i++ {
fmt.Printf("p[%d] == %d\n", i, p[i])
}
// slice index notation: (python)
fmt.Println("p[1:4] == ", p[1:4])
fmt.Println("p[:3] == ", p[:3])
fmt.Println("p[4:] == ", p[4:])
// slice index notation: (python)
fmt.Println("p[1:4] == ", p[1:4])
fmt.Println("p[:3] == ", p[:3])
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)
}