Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Looking for help with filling out the TODO portion of the following code snippet: void Stack::copy_of(const Stack& rhs){ //Makes an exact copy of Stack rhs

Looking for help with filling out the TODO portion of the following code snippet:

void Stack::copy_of(const Stack& rhs){ //Makes an exact copy of Stack rhs into this stack if (this != &rhs) { //makes sure that it does not make a copy of the stack itself while (!isEmpty()) pop(); // First empty the contents of this stack in case it has some items

if (!rhs.topPtr) topPtr = nullptr; // if rhs is an empty stack, this one will also be an empty stack else { //TODO // Make a copy of each node in rhs and link it to the list of this stack

} }

}

The header file it references is below:

class StackNode

{

public:

StackNode( int e = 0 , StackNode* n = nullptr){

item = e;

next = n;

}

int item;

StackNode* next;

};

class Stack{

public:

Stack(); // default constructor

Stack(const Stack& rhs); // copy constructor

~Stack(); // destructor

Stack& operator=(const Stack& rhs); // assignment operator

bool isEmpty();

void push(int newItem);

void pop();

int topAndPop();

int getTop() ;

void copy_of(const Stack& rhs);

private:

StackNode *topPtr; // pointer to the first node in the stack

};

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 Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions

Question

Describe key customer feedback collection tools.

Answered: 1 week ago

Question

Know what customers expect from the firm when they complain.

Answered: 1 week ago

Question

Understand why customers complain.

Answered: 1 week ago