Sort 2D array columns independently

Lamorak's Avatar, Join Date: Feb 2011
Newbie Member
Hello,

I have a 2D array of ints that I need to sort independently by columns in descending order.

For example right now I have:
0 1 2 3 4
5 19 7 33 9
10 11 24 13 14
15 16 43 30 19
20 21 22 23 24

and i want it to have the largest number in each column on top and and descend from there, but I don't know how to write the code.

any ideas would be great. Thanks!
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
if you had an 1d array what would you have as code?
0
Lamorak's Avatar, Join Date: Feb 2011
Newbie Member
I'd use
Code:
Arrays.sort(<array name>);
but I can't get it to work for a 2D array.
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
see this
http://www.roseindia.net/java/beginn...bbleSort.shtml
for 1d array.

hint:a 2d array MxN is ---->N 1d arrays Mx1


or you can do it like this
http://publicmind.in/blog/sorting-2d-array-java/

Last edited by virxen; 21Feb2011 at 02:59..