Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Be sure to read through Chapter 4 in your textbook before starting this assignment. In this assignment you will make some changes to the LinkedBag

image text in transcribedimage text in transcribed

Be sure to read through Chapter 4 in your textbook before starting this assignment. In this assignment you will make some changes to the LinkedBag class template from Chapter 4 . You will modify one of the existing methods and add a new method. Start with the first (nonrecursive) version of the LinkedBag class template from Chapter 4. I have put the files that you need to get started in the Programming Assignments section of Blackboard. Important: To use nullptr and other features of C++11, you need a compiler that is fairly recent. If your compiler was released in the last couple of years, you are probably okay. You may need to turn these features on in your IDE. For example, I typically use Dev-C++ with the GCC compiler TDM-GCC 4.9.2. To use C++11 features in Dev-C++, I had to select Tools/Compiler Options. Under the General tab in the "Add the following commands when calling the compiler" section I had to add: std=gnu++11 Requirement: Do not make any changes to the member variables (data members) for this class template. Your modified class template should only have 2 member variables - headPtr and itemCount. In particular, do not add a pointer to the last node in the linked list. To find the last node, you will need to use a temporary pointer and traverse the list. Modify add method As an academic exercise, revise the public method add in class template LinkedBag so that the new node is inserted at the end of the linked chain instead of at the beginning. Add a second remove method template. The prototype will be: bool remove ; interface. - Add the method prototype inside the class definition in LinkedBag.h. - Add the method implementation in LinkeBag.h. You can implement this method by borrowing code from the existing remove method. Here is an informal algorithm: canRemoveItem = bag not empty if canRemoveItem generate a random number in the range through itemcount - 1 think of the linked list as an array - the first node contains entry , etc. the random number indicates which node contains the entry to be deleted use a temporary pointer to traverse the linked list to the node to be deleted it is easier to remove the first node than any other node copy the entry from the first node to the node that contains the entry to be deleted delete the first node end if return canRemoveltem using namespace std; int main () int number; cout "Printing a list of 4 random integers in the range through 99" endl; for (int i=;i

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

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

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

Students also viewed these Databases questions

Question

=+ What typical employee will the IA compare him/

Answered: 1 week ago

Question

=+7 What is the overall cost of the international assignment?

Answered: 1 week ago