Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
OK basically i have a members club full of members and when i want to get all their names back
i use this code but what i really want to do is get them all back alphabetically, and i cant use the help of a java lib i have to use my own sort method. And before any one sends me links to java docs i have already tried but cannot figure it out.

Java
/**
 * List names.
 */
public void listNames() {
    for (int i = 0; i < members.size(); i++) {
        Member member = members.get(i);
        member.getName();
        StdOut.println(i + ":" + member.getName());
    }
}
          }
Posted
Updated 25-Apr-14 1:10am
v6
Comments
[no name] 24-Apr-14 7:48am    
Okay so what is stopping you from reading the documentation for the ArrayList class?
paul power 24-Apr-14 7:54am    
I have tried every thing to sort this out but i don't now what way to go about it
BupeChombaDerrick 25-Apr-14 13:03pm    
You can try heapsort, check my updated solution :)

You should be able to adopt the code when you copy it for the homework.

Your teacher can see if it's your code or another ones.

Please check the API:
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#toArray()[^]
 
Share this answer
 
Comments
paul power 24-Apr-14 11:09am    
Still stuck on this can any one even help with the first few lines
TorstenH. 25-Apr-14 6:42am    
What is the problem? Please ask specific and use "improve question" for it.
Try this

Java
public static void sortStringExchange( String  x [ ] ){
 
             Arrays.sort(x, new Comparator<string>() {
 
                @Override
                public int compare(String s1, String s2) {
 
                return s1.compareTo(s2);
 
           }
});
}


Well try heapsort http://en.wikipedia.org/wiki/Heapsort[^] http://codereview.stackexchange.com/questions/32606/implementation-of-heap-sort[^]

Hope this helps :)

BCD
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900