David O'Meara wrote:
One solution would be to make the class Comparable (ie able to be compared) and then feed the items to a java.util.TreeSet. The TreeSet will use the Comparable behaviour to retain the order, and then return the items in order. This may not be what you want, but it doesn't use either Comparator or Coollections.sort()
Agreed on the "may not be what you want" part...
If I was the professor, and told my students to not use collections.sort, or comparator/comparable in the assignment... and a student use TreeSet. I would be kinda impressed, that this student knows his/her API, and could even be a legal eagle one day.
But.... I would also fail the student for that assignment, for the student followed the letter of the assignment, but not the intent. The intent of such an assignment would surely be in the writing of your own sorting algorithm -- and not finding a class with a sorting algorithm included.
Henry