github.com/weedge/lib@v0.0.0-20230424045628-a36dcc1d90e4/sortx/tow_dimension_arr.go (about) 1 package sortx 2 3 type TwoDimensionalArray [][]int 4 5 // sort by column asc 6 func (e TwoDimensionalArray) Less(i, j int) bool { 7 for k := 0; k < len(e[i]); k++ { 8 if e[i][k] < e[j][k] { 9 return true 10 } else if e[i][k] == e[j][k] { 11 continue 12 } else { 13 return false 14 } 15 } 16 return true 17 } 18 19 func (e TwoDimensionalArray) Swap(i, j int) { 20 e[i], e[j] = e[j], e[i] 21 return 22 } 23 24 func (e TwoDimensionalArray) Len() int { 25 return len(e) 26 }