Implementing compareTo on linked list

Hey. Im trying to implement the compareTo method in java on a linked list. Not doing a very good job at it so hopeing for some help. Heres some code. Ive never done this so sorry if my questions sound retarted, or my code is way off.
Thanks
public class MutibleString implements Comparable<MutibleString>/*I want to compare 2 MutibleString's so is it best to put that in the<> or just not use these <>*/
{
/* Also do I need any spacific fields to implemtnt the Comparable interface right? these are what I have right now*/
         private Node head;
	private int size; 
	public char index;

/*
in here I have basic methods add remove charAt etc...
....
*/



public boolean compareTo(MutibleString that) 
	{
		if(this.MutibleString.compareTo(that.MutibleString))
		{
			return true;
		}
		return false;	
	}
}

Open in new window

theldroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ksivananthCommented:
>> if(this.MutibleString.compareTo(that.MutibleString))

actually you need to compare the fields here!

you have three fields head, size, index, you need to decide which field or weight of each field and then compare them! for e.g., if you just want to comapre based on the size,

 return size - that.getSize() ;
0
anilallewarCommented:
You are doing fine; the generics syntax is fine and you can use any arbitary fields for comparision...the compareTo() method is supposed to return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Suppose you say that if the size is what your comparision is based on (could be anything including elements in the Node class), you can have this code(remember it returns an int).

 public int compareTo(MutibleString that) {
        return this.getSize() - that.getSize();
    }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
theldroAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.