Skip to content

Instantly share code, notes, and snippets.

View umang94's full-sized avatar
👨‍💻

Umang Jain umang94

👨‍💻
View GitHub Profile
@umang94
umang94 / SortedMergeLL.cpp
Created August 19, 2014 11:41
Recursive function to merge two sorted Linked Lists.
struct node
{
int data;
struct node *next;
};
struct node* SortedMerge(struct node *a, struct node *b)
{
struct node *result;
if(a == NULL)
@umang94
umang94 / FindMergeNode.cpp
Last active August 29, 2015 14:04
A simple function to find the merge point of two Linked Lists in O(n) time and O(1) space
/*Make an interating pointer that goes forward every time till the end, and then jumps to the beginning of the opposite list, and so on. Create two of these, pointing to two heads. Advance each of the pointers by 1 every time, until they meet.*/
int FindMergeNode(Node *headA, Node *headB)
{
Node *p1 = headA;
Node *p2 = headB;
while(p1 != p2){
p1 = p1->next;
p2 = p2->next;
if(p1 == NULL)
p1 = headB;