Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions