通过行C中的第一个元素对矩阵的行进行排序

时间:2016-04-18 00:17:59

标签: c sorting matrix

我有一个矩阵:

{
  "bool": {
    "must": [
      {
        "term": {
          "productTypeID": {
            "value": 2
          }
        }
      },
      {
        "nested": {
          "query": {
            "bool": {
              "must": [
                {
                  "term": {
                    "stocks.statusID": {
                      "value": 1
                    }
                  }
                },
                {
                  "bool": {
                    "should": [
                      {
                        "term": {
                          "stocks.checkStockStatus": {
                            "value": false
                          }
                        }
                      },
                      {
                        "bool": {
                          "must": [
                            {
                              "term": {
                                "stocks.checkStockStatus": {
                                  "value": true
                                }
                              }
                            },
                            {
                              "range": {
                                "stocks.currentStockCount": {
                                  "gt": 0.0
                                }
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          },
          "path": "stocks"
        }
      }
    ]
  }
}

我需要的是这个输出:

3  3 -1 -1
1  1  1 -1
6  6  6  6
0 -1 -1 -1

我怎么能这样对它进行分类?

1 个答案:

答案 0 :(得分:0)

我希望这段代码可以帮到你。您应该自己做注释部分以获得结果。

#define RAW_NUM 4
#define COL_NUM  4  

int main () {
    int ** matrix = malloc (RAW_NUM * sizeof (int *));
    // you should be sure about successful allocation
    int i, j;
    for (i=0; i < RAW_NUM; i++) {
        matrix [i]= malloc (COL_NUM * sizeof (int);
        // you should be sure about successful allocation
    }
    // fill the matrix here
    for (i=0; i < RAW_NUM - 1; i++) {
        for (j=i +1; j < RAW_NUM; i++) 
        if (*matrix [i] > *matrix [j])
       {
           // please swap matrix [i] and matrix [j] here
       }
   }
}