I'm having trouble with this issue:
-I have to compare two linked lists and return 1 if they are equal or 0 if they are not.
The function is like this and I can not progress:
struct Node
{
int data;
struct Node *next;
}
int CompareLists(Node *headA, Node* headB)
{
/*se as duas forem vazias*/
if(headA->next==NULL && headB->next==NULL)
{
return 1;
}
if(headA->next==NULL || headB->next==NULL)
{
return 0;
}
while(headA->next!=NULL && headB->next!=NULL)
{
if(headA->data=!headB->data)
{
return 0;
}else{
return 1;
}
headA=headA->next;
headB=headB->next;
}
}
I think the problem is to go through the list ( headA = headA-> next ), but I do not know how to do it. Can anyone help me?