Given a Sorted Doubly Linked List in ( non-decreasing order ) and an element x , the task is to insert the element x into the correct position in the Sorted Doubly Linked List.
Example:
Input: LinkedList = 3581012 , x = 9
Output: 35891012Explanation: Here node 9 is inserted between 8 and 10 in the Doubly Linked-List.
Input: LinkedList = 141011 , x = 15
Output: 14101115Explanation: Here node 15 is inserted at end in the Doubly Linked-List.
Approach :
C
Java
Python
C#
JavaScript
3 5 8 9 10 12
Time Complexity: O(n) , where n is the number of nodes in the linked lsit.
Auxiliary Space: O(1)