Question: Using linked lists on C++ need assistance in two functions, insertSorted and removeSorted. I am a bit stuck and not able to wrap my head

Using linked lists on C++

need assistance in two functions, insertSorted and removeSorted. I am a bit stuck and not able to wrap my head around this so well. With the insert sorted function, not allowed to use looping statements. Only change the List header for functions, source can be used whichever way to test.

insert directions : Function insertSorted() inserts a new entry into the sorted list as indicated below: Using a pointer to create a new node that contains the new entry: Node newNodePtr=new Node(newEntry); If the list is empty, add the new node to the beginning of the list. If all the items in the list is greater than or equal to the newEntry, add the new node at the beginning of the list as well.Otherwise, insert the new node into the list right before the first node that contains the item that is greater than or equal to the newEntry. If all the entries in the list are less than newEntry, add the new entry at the end of the list. You may need following two pointers to complete the insertion: preNode=getNodeBefore(newEntry); curNode=preNode->getNext();

remove directions:

The Function removeSorted() removes a given entry from the sorted list. If the list is empty, return false. (removal failed) Otherwise, you may use following statements to find a pointer: preNode=getNodeBefore(anEntry); If preNode=NULL, that means either the item in the first node of the list is greater than anEntry or the item in the first node of the list is equal to anEntry. If the item is greater than the anEntry, then return false (anEntry is not in the list). If the item is equal to the anEntry, remove the first node of the list. If preNode!=NULL, find following pointer: curNode=preNode->getNext(); If curNode==NULL or curNode->getItem()>anEntry, return false (anEntry is not in the list). If curNode->getItem()==anEntry, remove the node that curNode points to.

header: https://pastebin.com/Sp6Ve0Rb

header(node): https://pastebin.com/981LAp7L

source: https://pastebin.com/FnhXbEHt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!