Question: 4. Given the algorithm for inserting new nodes into an ordered double linked list (or a portion of the algorithm) in real code, be able


4. Given the algorithm for inserting new nodes into an ordered double linked list (or a portion of the algorithm) in real code, be able to fill in the blanks. Note: There is no back pointer used in this function. bool MyDoubleLinkedList: :Insert (ListNode newNode) Assume ListNode is a structure and contains the variable int key; and ListNode *prev, next Assume the function returns true if it successfully inserts the node ListNode emp head if(head NULL) Check for inserting first node into an empty list return true; else Search for insert location while && Check for inserting at head of the list if return true else if (temp- next NULL) && (newNode >key temp->key)) Inserting at the tail else Insert elsewhere in the list Set newNode's pointers Set next pointer for node before newNode Set prev pointer for node after newNode return true; return false
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
