/
main.go
70 lines (55 loc) · 1.2 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"sort"
)
func intSortTest() {
var a = [...]int{1,66,2345,7,8,99,34,67}
//slice := a[:]
//sort.Ints(slice)
// fmt.Println(slice)
sort.Ints(a[:]) //入参需要时切片
fmt.Println(a)
}
func stringSortTest() {
//strs := make([]string,5)
strs := []string {"aaron","nina","allen","cici"}
fmt.Println(strs)
sort.Strings(strs)
fmt.Println(strs)
}
func floatSortTest(){
floats := []float64{0.123,234,55.44,9.888}
fmt.Println(floats)
sort.Float64s(floats)
fmt.Println(floats)
}
func intSearchTest() {
ints := []int{1,66,2345,7,8,99,34,67}
sort.Ints(ints)
index := sort.SearchInts(ints,99)
fmt.Println(ints)
fmt.Println("found with :", index)
}
func stringSearchTest(){
strs := []string{"aaron","nina","cici","allen"}
sort.Strings(strs)
fmt.Println(strs)
index := sort.SearchStrings(strs,"cici")
fmt.Println("found with index: ",index)
}
func floatSearchTest() {
floats := []float64{0.123,234,55.44,9.888}
sort.Float64s(floats)
fmt.Println(floats)
index := sort.SearchFloat64s(floats,55.44)
fmt.Println("found with index: ",index)
}
func main() {
intSortTest()
stringSortTest()
floatSortTest()
intSearchTest()
stringSearchTest()
floatSearchTest()
}