language: C++11 (gcc-4.7.2)
date: 192 days 22 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <cstdlib>
#include <iostream>
 
const int COL = 2;
 
int compare_rows(const void* lhs, const void* rhs)
{
    auto l = static_cast<const int(*)[COL]>(lhs);
    auto r = static_cast<const int(*)[COL]>(rhs);
    return (*r)[COL-1] - (*l)[COL-1];
}
 
int main()
{
    int Arr[3][COL] = {{1, 5}, {2, 8}, {3, 3}};
 
    std::qsort(Arr, 3, sizeof Arr[0], compare_rows);
 
// IDEone still has an outdated compiler, no range loops
//    for(auto& row: Arr)
//    {
//        for(auto& n: row)
//            std::cout << n << ' ';
//        std::cout << '\n';
//    }
    for(int row = 0; row < 3; ++row)
    {
        for(int col = 0; col < COL; ++col)
            std::cout << Arr[row][col] << ' ';
        std::cout << '\n';
    }
}