You are viewing a single comment's thread. Return to all comments →
Solution for Java using recursion:
if (data > llist.data) { if (llist.next == null || data < llist.next.data) { DoublyLinkedListNode newNode = new DoublyLinkedListNode(data); newNode.prev = llist; newNode.next = llist.next; if (llist.next != null) llist.next.prev = newNode; list.next = newNode; } else sortedInsert(llist.next, data); } else { if (llist.prev == null || data > llist.prev.data) { DoublyLinkedListNode newNode = new DoublyLinkedListNode(data); newNode.next = llist; newNode.prev = llist.prev; if (llist.prev != null) llist.prev.next = newNode; llist.prev = newNode; if (newNode.prev == null) return newNode; } else sortedInsert(llist.prev, data); } 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 →
Solution for Java using recursion: