compareTo method for doubly linked list

Hey, im trying to figure out how to write a comparTo method for my circular doubly linked list. Ive only writen one for primitive data types link int. So I cant figure out how to make it work for a linked list. Ive tried lots of different ways and combinations but I cant get the syntax right so it wont even compile. Im useing it for a sorting routine so I want it to look at 2 elements at a time and switch if one is greater or do nothing if they are the same.
Thanks
public class Node implements Comparable<Node>
{
	Node next;
	Node prev;
	Object data;
	
         @Override
	public int compareTo(Node that) 
	{
		if(( this.data).compareTo(that.data) > 0)
		{	
		return 1;
		}
		else
		{
		return 0;
		}
				
	}

//..... rest of Node class

Open in new window

theldroAsked:
Who is Participating?
 
objectsCommented:
should just need this

      public int compareTo(Node that)
      {
             return ((Comparable)data).compareTo((Compable)that.data);
        }

nb: you'll need to ensure the data objects implement Comparable (so you can compare them)
0
 
theldroAuthor Commented:
Thanks that worked good
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.