Created
May 9, 2016 19:26
-
-
Save jianminchen/904a955b78a56ece032f5b9a681f91fc to your computer and use it in GitHub Desktop.
HackerRank - LinkedList - compare two linked list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Compare two linked lists A and B | |
Return 1 if they are identical and 0 if they are not. | |
Node is defined as | |
struct Node | |
{ | |
int data; | |
struct Node *next; | |
} | |
*/ | |
int CompareLists(Node *headA, Node* headB) | |
{ | |
if(headA==NULL && headB==NULL) | |
return 1; | |
if(headA==NULL || headB == NULL) | |
return 0; | |
if(headA->data == headB->data) | |
return CompareLists(headA->next, headB->next); | |
else | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment