Interview Questions

Write a method to combine two two sorted linked list into one in sorted form with out using temporary Node.

Microsoft Interview Questions and Answers


(Continued from previous question...)

10. Write a method to combine two two sorted linked list into one in sorted form with out using temporary Node.

NODE MergedSortedList(NODE node1, NODE node2) {
if(NULL == node1 ) return node2;
if(NULL == node2) return node1;

if(node1->info info)
node1->next = MergedSortedList(node1->next,node2);
return node1;
}
else if(node1->info > node2->info)
node1->next = MergedSortedList(node1,node2->next);
return node2;
}
else if(node1->info == node2->info)
node1->next= node2;
node2->next= MergedSortedList(node1->next,node2->next);
return node1;
}
}

(Continued on next question...)

Other Interview Questions