March 2019
Intermediate to advanced
336 pages
9h 9m
English
The sort.Interface has the len, swap, and less methods, as shown in the following code:
// Len methodfunc (ThingSorter *ThingSorter) Len() int { return len(ThingSorter.Things)}// Swap methodfunc (ThingSorter *ThingSorter) Swap(i int, j int) { ThingSorter.Things[i], ThingSorter.Things[j] = ThingSorter.Things[j], ThingSorter.Things[i]}// Less methodfunc (ThingSorter *ThingSorter) Less(i int, j int) bool { return ThingSorter.byFactor(&ThingSorter.Things[i], &ThingSorter.Things[j])}
Read now
Unlock full access