Hey , for my class I have to create an Infinite Integer class which holds can hold a really, really large integer using a doubly linked list. It holds 3 integers per node, so 5,697,343 would be held like
[5] [697] [343]. I implemented my constructor and toString method fine, but I'm having trouble with my compareTo method which compares one Infinte Int to another. My logic and code seems right but the method always returns 0, heres the code-
Edit: It also seems that the size of the DLL is always 0, I dont know whats causing it as the .size() method works fine in the other methods.
public int compareTo(Object o)
{
System.out.println();
InfiniteInt passedInInt;
passedInInt = (InfiniteInt) o;
DLLNode ptr1 = this.head;
DLLNode ptr2 = passedInInt.head;
int compareInt = 0;
int breakInt = this.size();
if(this.size() > passedInInt.size())
compareInt = 1;
else if(this.size() < passedInInt.size())
compareInt = -1;
else
{
System.out.println("--------------");
System.out.println(this + " this is whats inside the first DLLNode" );
System.out.println(passedInInt + " this is whats inside the other DLLNode");
System.out.println(this.size() +" this is the size of the first DLLNode");
System.out.println(passedInInt.size() + " this is the size of the other DLLNode");
for(int i = 0; i < this.size(); i++)
{
System.out.println(ptr1);
System.out.println(ptr2);
if((Integer)ptr1.data > (Integer)ptr2.data)
{
compareInt = 1;
i = breakInt;
}
else if((Integer)ptr2.data > (Integer)ptr1.data)
{
compareInt = -1;
i = breakInt;
}
ptr1 = ptr1.next;
ptr2 = ptr2.next;
}
}
return compareInt;
}
}