Skip to content

Instantly share code, notes, and snippets.

@umang94
Created August 19, 2014 11:41
Show Gist options
  • Save umang94/c0487a571b06786eda59 to your computer and use it in GitHub Desktop.
Save umang94/c0487a571b06786eda59 to your computer and use it in GitHub Desktop.
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)
return b;
if (b == NULL)
return a;
if (a ->data <= b->data)
{
result = a;
result->next = SortedMerge(a->next, b);
}
else
{
result = b;
result->next = SortedMerge(a,b->next);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment