theldro
asked on
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
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;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
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() ;