Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Sort 2D array columns independently (http://www.go4expert.com/forums/sort-2d-array-columns-independently-t25027/)

Lamorak 19Feb2011 07:49

Sort 2D array columns independently
 
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!

virxen 20Feb2011 03:28

Re: Sort 2D array columns independently
 
if you had an 1d array what would you have as code?

Lamorak 20Feb2011 08:26

Re: Sort 2D array columns independently
 
I'd use
Code:

Arrays.sort(<array name>);
but I can't get it to work for a 2D array.

virxen 21Feb2011 02:53

Re: Sort 2D array columns independently
 
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/


All times are GMT +5.5. The time now is 19:16.