zoukankan      html  css  js  c++  java
  • golang 二维切片

    初始化:
    res := make([][length]int, length),
    例如:
    res := make([][2]int, 10)
    fmt.Println(res)
    输出:
    [[0 0] [0 0] [0 0] [0 0] [0 0] [0 0] [0 0] [0 0] [0 0] [0 0]]
     
    或者
    a := [][]float64{
            {1, 2, 3, 4},
            {12, 21, 3, 14},
            {1, 1, 2, 3},
            {2, 3, 1, 6},
            {2, 2, 3, 3},
            {1, 1, 1, 1}}
    
    
    排序:
    //根据二维切片的第一个属性从大到小排序,第二个属性默认是递增顺序
    people := [][]int{{9, 0}, {7, 0}, {1, 9}, {3, 0}, {2, 7}, {5, 3}, {6, 0}, {3, 4}, {6, 2}, {5, 2}}
    less := func(i, j int) bool {
    	if people[i][0] == people[j][0] {
    		return people[i][1] < people[j][1]
    	}
    	return people[i][0] > people[j][0]
    }
    //调用排序函数
    sort.Slice(people, less)
    fmt.Println(people)
    //输出
    //[[9 0] [7 0] [6 0] [6 2] [5 2] [5 3] [3 0] [3 4] [2 7] [1 9]]
    
  • 相关阅读:
    Linux
    python 鸢尾花数据集报表展示
    python 词云
    毕业设计回顾
    editor.md
    杂记
    垃圾回收器
    杂记
    随笔
    杂记
  • 原文地址:https://www.cnblogs.com/nyist-xsk/p/11365412.html
Copyright © 2011-2022 走看看