1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 s
:= []int{5, 2, 6, 3, 1, 4} // unsorted
16 // Output: [1 2 3 4 5 6]
19 func ExampleReverse() {
20 s
:= []int{5, 2, 6, 3, 1, 4} // unsorted
21 sort
.Sort(sort
.Reverse(sort
.IntSlice(s
)))
23 // Output: [6 5 4 3 2 1]
36 sort
.Slice(people
, func(i
, j
int) bool { return people
[i
].Name
< people
[j
].Name
})
37 fmt
.Println("By name:", people
)
39 sort
.Slice(people
, func(i
, j
int) bool { return people
[i
].Age
< people
[j
].Age
})
40 fmt
.Println("By age:", people
)
41 // Output: By name: [{Alice 55} {Bob 75} {Gopher 7} {Vera 24}]
42 // By age: [{Gopher 7} {Vera 24} {Alice 55} {Bob 75}]