Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. /*
  2. Compare two linked lists A and B
  3. Return 1 if they are identical and 0 if they are not.
  4. Node is defined as
  5. struct Node
  6. {
  7. int data;
  8. struct Node *next;
  9. }
  10. */
  11. int CompareLists(Node *headA, Node* headB)
  12. { if((headA==NULL) && (headB==NULL)) return 1;
  13.  
  14. while(1){
  15. if((headA->data)!=(headB->data)) return 0;
  16. else if(((headA!=NULL) && (headB==NULL))||((headA==NULL) && (headB!=NULL))) return 0;
  17. else if((headA==NULL) && (headB==NULL)) break;
  18. else {
  19. headA=headA->next;
  20. headB=headB->next;
  21. }
  22. }
  23. return 1;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement