在切片内对整数切片进行排序[关闭]

I'm trying to sort slice of int inside a slice, for example :

slices := make([][]int32, 0)
slices = append(slices, []int32{10,22})
slices = append(slices, []int32{13,22})
slices = append(slices, []int32{12,22})
// [[10 22] [13 22] [12 22]]
// to become 
// [[10 22] [12 22] [13 22]] (ascending)
// *by the first element in slice

i had no idea for that, but i was thinking about append and prepend after check

All you need is use Slice from sort package

package main

import (
    "fmt"
    "sort"
)
func main() {
    a := [][]int{[]int{10,3}, []int{5,12}, []int{5, 3}, []int{1,1}}
    fmt.Printf("before: %v
", a)
    sort.Slice(a, func(i,j int) bool{ return a[i][0] < a[j][0]})
    fmt.Printf("after: %v
", a)
}

For stable sort use, sort.SliceStable instead.