Saturday, January 22, 2011

Merge two linked lists: Node* MergeList(Node *list1, Node* list2). Do not create a node in the function while merging the lists.

Struct Node{
int data;
struct node* p;
}

we are assuming that both the given list are sorted.
node mergeSort(node a, node b){
if(a == null) return b;
if(b == null) return a;
if(a.value <= b.value){
a.next = mergeSort(a.next, b);
retrun a;
}else{
b.next = mregeSort(a, b.next);
return b;
}
}

No comments:

Post a Comment