Dec 2, 2012 at 8:16pm UTC
You got the indexes backwards in the swap() call.
EDIT: How many elements are in a row? rows???
Note: Your code is swapping the columns, not the rows.
Last edited on Dec 2, 2012 at 8:24pm UTC
Dec 2, 2012 at 8:50pm UTC
OK, thank you, i managed to solve it. :) Thanks a lot!
Last edited on Dec 2, 2012 at 8:54pm UTC
Dec 2, 2012 at 9:00pm UTC
You're welcome.
I hope you see how to solve problems like this now.
That's why I wouldn't just cave in and give the solution.
Dec 2, 2012 at 9:09pm UTC
Em, i found one more thing i was trying just now,... i cant find the spot to put in a 'cout' for the row counter, so there is in front of every row (1., 2., 3., 4., 5.)
like this:
3. 2 5 8 15
1. 5 3 4 12
4. 7 2 1 10
...etc...
i tried to put in an extra for loop only for the counter but in showes the 1. -5. between each numbers :S
Last edited on Dec 2, 2012 at 9:16pm UTC
Dec 2, 2012 at 9:21pm UTC
You need to display what the row # was before sorting right?
Like in your 1st post?
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
Create another array for the row numbers and sort it alongside the others.
Last edited on Dec 2, 2012 at 9:21pm UTC
Dec 2, 2012 at 9:31pm UTC
But that means i have to use this numbering array as the numberng system for the first output aswell, right?
because in the first part i just use to pint out and integer from the for loop and add ed +1 to start counting from 1 - 5 ...
Dec 2, 2012 at 9:33pm UTC
That's right. The row numbers will sort just like rowsums and the row elements do. Use these for the 1st number on each line.
Initially int rowNums[5] = {1,2,3,4,5};
Last edited on Dec 2, 2012 at 9:35pm UTC