You might want to look at classes TreeSet and interface Comparable. Check the
Java Documentation for more information. A TreeSet is an abstract data type representing a set that maintains an order on its elements. These elements must be Comparable. Also, method sort from Collections might be worth looking at.
If you want to implement the actual sorting, you might want to look at
- Insertion sort (small number of elements)
- Merge sort (good worst case time for large number of elements)
- Quicksort (good expected time for large number of elements)
- Counting sort (if you know the maximum capacity and are willing to waste some space,
this will be the fastest)
(Wikipedia them for pseudocodes).
[ April 03, 2008: Message edited by: Alberto Caraz ]
[ April 03, 2008: Message edited by: Alberto Caraz ]