Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note that this is an incorrect implementation that ignores the position desired and always inserts at the beginning of the list. As a result, note

Note that this is an incorrect implementation that ignores the position desired and always inserts at the beginning of the list. As a result, note how the test result for the entry at position 4 fails! Your job is to fix this function so it inserts in the correct position in the list. Once you've fixed it you should see the correct output from the tests.

template bool LinkedList::insert(int newPosition, const ItemType& newEntry) { bool ableToInsert = (newPosition >= 1) && (newPosition <= itemCount + 1); if (ableToInsert) { // Create a new node containing the new entry Node* newNodePtr = new Node(newEntry);

// This implementation ignores newPosition, and always put the new // item at the beginning of the list. // Your assignment is to correctly insert the item into newPosition newNodePtr->setNext(headPtr); headPtr = newNodePtr;

itemCount++; // Increase count of entries } // end if return ableToInsert; } // end insert

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

Question What is a Roth 403 (b) plan?

Answered: 1 week ago

Question

Question Can a Keogh plan fund be reached by the owners creditors?

Answered: 1 week ago