Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program reads the first input as the number of integer input values that follow, and then reads and stores that many following input values

The program reads the first input as the number of integer input values that follow, and then reads and stores that many following input values into listOfMuskrats. Complete the MuskratsList class destructor. The destructor prints "Deleting the nodes of MuskratsList", followed by a new line, and then calls the destructor of each node in the linked list.

Ex: If the input is 2 16 5, then the output is:

Deleting the nodes of MuskratsList Deallocating MuskratNode (5) Deallocating MuskratNode (16) 

#include using namespace std;

class MuskratNode { public: MuskratNode(int kitsValue); ~MuskratNode();

int kits; MuskratNode* next; };

MuskratNode::MuskratNode(int kitsValue) { kits = kitsValue; }

MuskratNode::~MuskratNode() { cout << "Deallocating MuskratNode (" << kits << ")" << endl; }

class MuskratsList { public: MuskratsList(); ~MuskratsList(); void Prepend(int kitsValue); private: MuskratNode* head; };

MuskratsList::MuskratsList() { head = nullptr; }

/* Your code goes here */

void MuskratsList::Prepend(int kitsValue) { MuskratNode* newNode = new MuskratNode(kitsValue); newNode->next = head; head = newNode; }

int main() { MuskratsList* listOfMuskrats = new MuskratsList(); int inputValue; int muskratCount; int i; cin >> muskratCount; for (i = 0; i < muskratCount; i++) { cin >> inputValue; listOfMuskrats->Prepend(inputValue); }

delete listOfMuskrats; return 0; }

c++ and please please make it correct

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

Data Analytics Systems Engineering Cybersecurity Project Management

Authors: Christopher Greco

1st Edition

168392648X, 978-1683926481

More Books

Students also viewed these Databases questions

Question

Is the tone professional, polite, and appropriately formal? (350)

Answered: 1 week ago