aspose file tools*
The moose likes Beginning Java and the fly likes sorting double nodes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sorting double nodes" Watch "sorting double nodes" New topic
Author

sorting double nodes

christopher persinger
Greenhorn

Joined: Aug 23, 2005
Posts: 20
Okay I need to create a sort method that will sort double nodes into an ascending list. The elments in the nodes will be Strings so I will need to use a compareTo method in order to tell if it is greater than or less than the String being compared to. Well in our instructions, we are supposed to be using generics. So how can I use a compareTo method if we are using generics? Or is there another way to go about using the insertion sort method of sorting double nodes in a list?? Thanks in advance!
Mark Van Tuyl
Ranch Hand

Joined: Mar 22, 2002
Posts: 60
As long as the Objects being compared implement the compareTo() method, there shouldn't be a problem. Your example is using String's, and the String class implements that method.


<a href="http://www.catb.org/~esr/faqs/smart-questions.html" target="_blank" rel="nofollow">How To Ask Smart Questions</a>
christopher persinger
Greenhorn

Joined: Aug 23, 2005
Posts: 20
But since we are using generics.. how would i create an object to compare?
christopher persinger
Greenhorn

Joined: Aug 23, 2005
Posts: 20
basically what im trying to ask is.. how would you use the compareTo method with generics?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I am not entirely sure what you are asking. Can you post some code for your sort method, and even the class that contains it?

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sorting double nodes