Microsoft Interview Question
1,274 Interview Reviews |
Back to all Microsoft Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Development Engineer In Test (SDET) at Microsoft:
merge 2 sorted linked lists .
See more for this Microsoft Software Development Engineer In Test (SDET) Interview
Helpful Question?
Yes |
No
Inappropriate?



0 of 0 people found this helpful
by Valentino:
public Node Merge(Node l1, Node l2)
{
if (l1 == null) return l2;
if (l2 == null) return l1;
Node root = new Node();
Node first = root;
while (l1 != null && l2 != null)
{
Node swap = (l1.Data < l2.Data) ? l1 : l2;
root = root.Next = swap;
l1 = l1 == swap ? l1.Next : l1;
l2 = l2 == swap ? l2.Next : l2;
}
root.Next = (l2 == null) ? l1 : l2;
return first.Next;
}