Created
April 9, 2016 21:03
-
-
Save miniharryc/f2940937a34eb901a6c65dddab4f3de6 to your computer and use it in GitHub Desktop.
HackerRank compare two linked lists
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) | |
{ | |
Node *a = headA, *b = headB; | |
while( a && b && ( a->data == b->data ) ) { | |
a = a->next; | |
b = b->next; | |
} | |
return a == b; //both are null pointers | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment