-
Notifications
You must be signed in to change notification settings - Fork 20
/
sort.go
41 lines (31 loc) · 679 Bytes
/
sort.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
package tldr
type ByWeight []*Edge
func (b ByWeight) Len() int {
return len(b)
}
func (b ByWeight) Swap(i, j int) {
b[i], b[j] = b[j], b[i]
}
func (b ByWeight) Less(i, j int) bool {
return b[i].weight < b[j].weight
}
type ByScore []*Rank
func (b ByScore) Len() int {
return len(b)
}
func (b ByScore) Swap(i, j int) {
b[i], b[j] = b[j], b[i]
}
func (b ByScore) Less(i, j int) bool {
return b[i].score < b[j].score
}
func ReverseEdge(num []*Edge) {
for i, j := 0, len(num)-1; i < j; i, j = i+1, j-1 {
num[i], num[j] = num[j], num[i]
}
}
func ReverseRank(num []*Rank) {
for i, j := 0, len(num)-1; i < j; i, j = i+1, j-1 {
num[i], num[j] = num[j], num[i]
}
}