Sort 2D array columns independently

Discussion in 'Java' started by Lamorak, Feb 19, 2011.

  1. Lamorak

    Lamorak New Member

    Joined:
    Feb 19, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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!
     
  2. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    if you had an 1d array what would you have as code?
     
  3. Lamorak

    Lamorak New Member

    Joined:
    Feb 19, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I'd use
    Code:
    Arrays.sort(<array name>);
     
    but I can't get it to work for a 2D array.
     
  4. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    Last edited: Feb 20, 2011

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice