Created
August 19, 2014 11:41
-
-
Save umang94/c0487a571b06786eda59 to your computer and use it in GitHub Desktop.
Recursive function to merge two sorted 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
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