You are viewing a single comment's thread. Return to all comments →
Simpler code in java
static DoublyLinkedListNode sortedInsert(DoublyLinkedListNode head, int data) { DoublyLinkedListNode temp=head; DoublyLinkedListNode currentnode=new DoublyLinkedListNode(data); if(head.data>data) { currentnode.next=head; head=currentnode; } else { while(temp.next!=null && temp.data<data) { temp=temp.next; } if(temp.next==null && temp.data<data) { temp.next=currentnode; currentnode.prev=temp; return head; } else{ currentnode.prev=temp.prev; currentnode.next=temp; currentnode.prev.next=currentnode; temp.prev=currentnode; } } return head; }
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 →
Simpler code in java