You are viewing a single comment's thread. Return to all comments →
*PYTHON Whenever we have to change the head ,its best practice to create a dummy node as head
def sortedInsert(llist, data): dummy=DoublyLinkedListNode(float('-inf')) dummy.next=llist llist.prev=dummy y=dummy while (dummy): previous=dummy if(dummy.next and dummy.next.data>=data and dummy.data<=data): x=DoublyLinkedListNode(data) dummy.next,x.next=x,dummy.next x.prev=dummy x=x.next.prev return y.next dummy=dummy.next x=DoublyLinkedListNode(data) x.prev=previous previous.next=x return y.next
Seems like cookies are disabled on this browser, please enable them to open this website
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →