We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My solution with one pointer - seems like two pointers helps clear a lot of the thought process up :) need to start getting good ideas like that haha
im assuming the space and time complexity are the same
NodeSortedInsert(Nodehead,intdata){Nodeins=newNode();ins.data=data;Nodeitr=head;//case: empty list if(head==null){returnins;//case: at begining of list }elseif(head.data>data){ins.next=head;head.prev=ins;returnins;}else{while(itr.data<data){if(itr.next==null){// case: at end of listitr.next=ins;ins.prev=itr;returnhead;}else{itr=itr.next;}}// case: somewhere in middleitr.prev.next=ins;ins.prev=itr.prev;itr.prev=ins;ins.next=itr;returnhead;}}
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →
My solution with one pointer - seems like two pointers helps clear a lot of the thought process up :) need to start getting good ideas like that haha
im assuming the space and time complexity are the same