HELP 2d arrays sort by sum of numbers in a row

12/02/2012 14:41 Hikarim#1
Hi, i'd like to ask for some help about a problem i got... So i got this code right now:
Code:
Code:
        const int rows = 5;
        const int cols = 3;
        int tocke = 0;
       
        int tekmovalci[rows][cols]={{7, 6, 9},
                                    {8, 7, 8},
                                    {6, 9, 10},
                                    {7, 7, 9},
                                    {8, 8, 10}};
                                       
        for(int r=0; r<rows; r++){
                cout << r+1 << ". ";
                for(int c=0; c<cols; c++){
                        cout << tekmovalci[r][c] << " ";
                        tocke += tekmovalci[r][c];       
                }
                cout << tocke << endl;
                tocke = 0;       
        }
and the 'int tocke' represents the sum of all numbers in a row, and now i'd like to sort the output by the value of sum.

this is the current output:
1. 7 6 9 22
2. 8 7 8 23
3. 6 9 10 25
4. 7 7 9 23
5. 8 8 10 26

and i want it like this:
5. 8 8 10 26
3. 6 9 10 25
2. 8 7 8 23
4. 7 7 9 23
1. 7 6 9 22

so can anyone post me a solution of this ??
12/02/2012 15:45 kissein#2
You can use an stack container. That would be last item in first item out.
see also
[Only registered and activated users can see links. Click Here To Register...]