insert node in doubly linked list steps code example
Example: how to Inserting a Node Into a Sorted Doubly Linked List
class DoublyLinkedListNode:
def __init__(self, node_data):
self.data = node_data
self.next = None
self.prev = None
def sortedInsert(head, data):
node = DoublyLinkedListNode(data)
if (head == None):
return node
elif (data < head.data):
node.next = head
head.prev = node
return node
else:
node = sortedInsert(head.next, data)
head.next = node
node.prev = head
return head