|
-
May 28th, 2003, 01:02 PM
#1
Thread Starter
Addicted Member
array sort, comparable?
I'm interested in using the sort method of the array class.
sort(Object[] a, Comparator c)
I have anarray of ADTs cal them X[]. This type has many public varibles in the class. I'd like to sort the array by these varibles, this possible with X.sort(X, ???);?
Any other ideas? Or am i going to have to write the sorting method???
Thanks!
NOMAD
-
Jun 2nd, 2003, 01:36 AM
#2
Two options:
1) Let X implement Comparable, implement compare and use the sort function without a Comparator argument.
2) Don't implement Comparable, instead write a custom class that implements Comparator (could be an anonymous class) and pass it as Comparator argument.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jun 2nd, 2003, 11:16 AM
#3
Thread Starter
Addicted Member
Good ideas
Thanks Corned Bee, I like idea #2.
NOMAD
-
Jun 2nd, 2003, 12:16 PM
#4
Depending on your data type #1 might make more sense. For example I explained a guy in the C++ forum today how to sort highscores using a std::set (similar to java.util.TreeSet). A highscore type should be Comparable.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|