Created
August 12, 2015 11:05
-
-
Save code4sharing/363a4651be5209646aef to your computer and use it in GitHub Desktop.
Find merge point between two linkedlist
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
/* | |
Insert Node at the end of a linked list | |
head pointer input could be NULL as well for empty list | |
Node is defined as | |
class Node { | |
int data; | |
Node next; | |
} | |
*/ | |
int FindMergeNode(Node headA, Node headB) { | |
// Complete this function | |
// Do not write the main method. | |
Node tempB=new Node(); | |
while(headA!=null) | |
{ | |
tempB=headB; | |
while(tempB!=null) | |
{ | |
if(headA==tempB) | |
{ | |
return tempB.data; | |
} | |
tempB=tempB.next; | |
} | |
headA=headA.next; | |
} | |
return headA.data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment