Sorted insertion in doubly linked list

There are three possible position to insert new node of linked list. inserting beginning position , inserting node at end of linked list and inserting node at specified position of between two nodes. There is all situation are used to sorted insertion in doubly linked list.

Hint: 1) Initial linked list is empty so insert first node of linked list and assign this address to head pointer of linked list.

2) In other case linked list are not empty then find linked list node which are greater than newly inserted nodes. In this situation are three possibility.

a) When if first node is largest then add this node to front of linked list and on head pointer are assign the reference of this new node. This is situation of insert node at beginning.

b) If there is not find any big node of new inserted node in existing linked list then this node are inserted on last position of linked list. This is situation of insert node at end position.

c) If insert node is found in intermediate position, then add this node of this position.

Note that doubly linked list every node are two pointer fields that pointer are hold the reference of next and previous node address. When inserting new node that is also stratified this properties.

Suppose we are inserted the following (5,3,11,4,6,1,8,12) node in a sequence.

insert sorted doubly linked list

Here given code implementation process.



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







© 2021, kalkicode.com, All rights reserved