Question
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started