You are viewing a single comment's thread. Return to all comments →
My Java 8 Solution
public static DoublyLinkedListNode sortedInsert(DoublyLinkedListNode llist, int data) { DoublyLinkedListNode newNode = new DoublyLinkedListNode(data); if (llist == null) { return newNode; } DoublyLinkedListNode current = llist; while (current != null ) { if (current.data >= data) { if (current.prev == null) { newNode.next = current; current.prev = newNode; return newNode; } DoublyLinkedListNode prev = current.prev; current.prev = newNode; prev.next = newNode; newNode.next = current; newNode.prev = prev; return llist; } if (current.next == null) { current.next = newNode; newNode.prev = current; return llist; } current = current.next; } return llist; }
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 →
My Java 8 Solution