Hey I need help making a isEqual method in my singly linked class. The goal is to prove that both list have the same elements without necessarily having the same order. Now my method does call a different method in the node class, and it's job is to to search the for the element int the list. Here are two different outputs:
Output1:
Size of list1:
5
[1][2][4][5][7]
[1][7][2][4][5]
First list contains 4:
true
list1 is equal tolist2:
true
Output2:
Size of list1:
5
[1][2][4][5][7]
[1][9][2][4][5]
First list contains 4:
true
list1 is equal tolist2:
true
Please help!!!
public boolean isEqual(SLinkedList obj){
int count = 0;
Node cursor;
Node head2 = obj.head;
Node tmp = obj.head.getNext();
cursor = Node.listSearch(head.getNext(), tmp.getElement());
while(cursor!= null){
count++;
while(head2.getNext()!= null){
head2 = head2.getNext();
}
cursor = Node.listSearch(head.getNext(), head2.getElement());
if(count==size) cursor = null;
}
if(count == size){
return true;
}
return false;
}