Skip to main content

Sorted merge of two sorted doubly linked lists

Assume that we are two sorted doubly linked list, and we are combined this linked single one. The resultant of this linked list should be in a sorted order. For example.

First Sorted Doubly Linked List Second Sorted Doubly Linked List Sorted merge of two sorted doubly linked list

This last linked list are resultant of merge two sorted list. Before write an algorithm to of this problem consider following test cases.

1) When given anyone linked list are empty then we cannot merge linked list.

2) There is possible to compare both linked list are not same number of nodes. but the sequence of both linked list is ascending order.

head1 : 1->9->11->NULL
head2 : 4->5->9->18->NULL
resultant head1: 1->4->5->9->9->11->18

3) There are possible to exist repeated element in linked list. See above example here 9 is exist in a both linked list.

Here given code implementation process.





Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment