@@ -33,54 +33,38 @@ func click(t string) {
3333 sort .Stable (custom {tracks ,
3434 func (x , y * Track ) bool {
3535 return x .Title < y .Title
36- },
37- func (x , y * Track ) {
38- x .Title , y .Title = y .Title , x .Title
3936 }})
4037 case "artist" :
4138 sort .Stable (custom {tracks ,
4239 func (x , y * Track ) bool {
4340 return x .Artist < y .Artist
44- },
45- func (x , y * Track ) {
46- x .Artist , y .Artist = y .Artist , x .Artist
4741 }})
4842 case "album" :
4943 sort .Stable (custom {tracks ,
5044 func (x , y * Track ) bool {
5145 return x .Album < y .Album
52- },
53- func (x , y * Track ) {
54- x .Album , y .Album = y .Album , x .Album
5546 }})
5647 case "year" :
5748 sort .Stable (custom {tracks ,
5849 func (x , y * Track ) bool {
5950 return x .Year < y .Year
60- },
61- func (x , y * Track ) {
62- x .Year , y .Year = y .Year , x .Year
6351 }})
6452 case "length" :
6553 sort .Stable (custom {tracks ,
6654 func (x , y * Track ) bool {
6755 return int64 (x .Length ) < int64 (y .Length )
68- },
69- func (x , y * Track ) {
70- x .Length , y .Length = y .Length , x .Length
7156 }})
7257 }
7358}
7459
7560type custom struct {
7661 t []* Track
7762 less func (x , y * Track ) bool
78- swap func (x , y * Track )
7963}
8064
8165func (x custom ) Len () int { return len (x .t ) }
8266func (x custom ) Less (i , j int ) bool { return x .less (x .t [i ], x .t [j ]) }
83- func (x custom ) Swap (i , j int ) { x .swap ( x . t [i ], x .t [j ]) }
67+ func (x custom ) Swap (i , j int ) { x .t [i ], x .t [j ] = x . t [ j ], x . t [ i ] }
8468
8569type Track struct {
8670 Title string
0 commit comments