MiF Posted July 11, 2011 Share Posted July 11, 2011 (edited) I have been stuck with problem about hour already, and without working solution, so i think it's time to ask for help.Problem is this. I have 2 dimension array ( [inf.] [3] ) where first data is name (first and last name), second is age and third is city. Now i need to sort this array of data in order of age (from older to younger).I am coding it in java, and i can use all libraries which come with java, but no outside ones.There might be easy solution for this, but i am just locked up (as we say here in finland) :/ Edited July 11, 2011 by MiF Quote Link to comment
Raptor Posted July 11, 2011 Share Posted July 11, 2011 Well, I only can help you by bumping this Maybe the Programming Experts weren't on when your Topis was on the Front Page :C Quote Link to comment
Clavus Posted July 11, 2011 Share Posted July 11, 2011 What exactly is the problem? Are you searching for a sorting algorithm to use or can't you write decent java code in the first place. Quote Link to comment
MrZunz Posted July 11, 2011 Share Posted July 11, 2011 (edited) First off all you need to store all those arrays, in an array... Edited July 11, 2011 by MrZunz Quote Link to comment
Clavus Posted July 11, 2011 Share Posted July 11, 2011 Turning them into an ArrayList data structure is going to make your life a lot easier to begin with. Quote Link to comment
MiF Posted July 11, 2011 Author Share Posted July 11, 2011 What exactly is the problem? Are you searching for a sorting algorithm to use or can't you write decent java code in the first place.I have alghorithm (which works). Problem itself is this;i have this 2d array with this data (left to right is first dimension, up to down is second):I need to sort it to this:Turning them into an ArrayList data structure is going to make your life a lot easier to begin with.(Ninja'd)Okey got to check that out -> Quote Link to comment
Kikkers Posted July 11, 2011 Share Posted July 11, 2011 1. make a class to contain your values2. let that class implement the Comparable interface3. implement the compareTo() method with your custom sortingNow, by implementing Comparable, you can use some extra collection features such as this sort method for lists (that includes ArrayList) or )"]this one for simple arraysThere are more ways to do it, like comparators, but they are functionally similar (and not any easier anyway). You should avoid writing your own sorting methods, as the java collection framework is already optimized. Quote Link to comment
Navo Posted July 11, 2011 Share Posted July 11, 2011 I have absolutely no idea what people are talking about in this topic. Quote Link to comment
TechnoNegro Posted July 12, 2011 Share Posted July 12, 2011 (edited) i think i could understand that in other langue, like finnish or english. Edited July 12, 2011 by TechnoNegro Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.