Well i have made a 2d Array and filled it with random numbers...
and while printing(cout) it out i added a sum of numbers(i each row) at the end.
Now i would like to sort the output(cout) according to the sum...
Yes, but thats basically useless for what i wanna get i think, as i want to sort the rows of the first array according to the sums that i have sorted in the array "mesta"
For the names and ages problem:
As you are sorting the ages array, every time you swap elements in the ages array make the same swap in the names array.
This will keep the names and ages associated.
For your problem:
As you are sorting the rowsums[] array, every time you swap elements in the rowsums[] array make the same swap of rows in the 2d array.
EDIT: We are talking about 1 line of code being added to your sort function!
Hint: The 1st half of it looks like line 5. The 2nd half looks like line 21.
ok,i get that but how do i swap the wholes rows? :S
-can oyu please write me a working sample of how you sort two arrays like u mention? so i can see and figure it out... and make it work for me...?
No. Think about my last post harder first. It's right in front of you.
Which line in the code you gave swaps elements in the mesta array?
use the swap() function to swap each of the elements in row nStartIndex
with those in row nSmallestIndex, just like you are doing with the elements of mesta.
Well i tried to do the age and name thing(i used index number instead of names), but it just sorts both arrays descending, i dont get to make it so it keeps age with the index :S
Yes, a for loop around the swap line. No, you don't need to transform the array to 1D.
Think about the names, ages problem. names were string objects so they can be directly swapped, but what if we were stuck with char arrays and not allowed to use strcpy()?
You would have to swap the names character by character.