Visualize merging two sorted doubly linked lists into one sorted list!
Hi! I'm Teju 👋 We are given two sorted doubly linked lists and need to merge them into a single sorted doubly linked list.
The merge should preserve the sorted order and maintain proper prev/next links.
Input:
• N1 → values of List 1
• N2 → values of List 2
Output: One merged sorted doubly linked list
Example:
List 1: 1 ↔ 3 ↔ 5
List 2: 2 ↔ 4 ↔ 6
→ Merged: 1 ↔ 2 ↔ 3 ↔ 4 ↔ 5 ↔ 6
We use a method similar to merge step in merge sort: compare heads of both lists and always pick the smaller one.
Enter details for both lists and click "Build Lists"...
Merged Sorted Doubly Linked List: