You are viewing a single comment's thread. Return to all comments →
C++
DoublyLinkedListNode* sortedInsert(DoublyLinkedListNode* llist, int data) { DoublyLinkedListNode* a = 0; DoublyLinkedListNode* b = llist; for (; b && b->data < data; a = b, b = b->next) {} auto newNode = new DoublyLinkedListNode(data); if (b != nullptr) { b->prev = newNode; newNode->next = b; } if (a != nullptr) { a->next = newNode; newNode->prev = a; } else { return newNode; } 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 →
C++