Question: Using the following templete class: #include StackP.h // header file #include // for cout using namespace std; template Stack :: Stack() : topPtr(nullptr) { }

Using the following templete class:

#include "StackP.h" // header file #include  // for cout using namespace std; template  Stack :: Stack() : topPtr(nullptr) { } template  Stack :: Stack(const Stack& aStack) { if (aStack.topPtr == nullptr) topPtr = nullptr; // original list is empty else { // copy first node topPtr = new StackNode; topPtr->item = aStack.topPtr->item; // copy rest of list StackNode *newPtr = topPtr; // new list pointer for (StackNode *origPtr = aStack.topPtr->next; origPtr != nullptr; origPtr = origPtr->next) { newPtr->next = new StackNode; newPtr = newPtr->next; newPtr->item = origPtr->item; } newPtr->next = nullptr; } } template  Stack ::~Stack() { // pop until stack is empty while (!isEmpty()) pop(); } template  bool Stack ::isEmpty() const { return topPtr == nullptr; } template  bool Stack ::push(const StackItem &newItem) { // create a new node StackNode *newPtr = new StackNode; newPtr->item = newItem; // insert the new node newPtr->next = topPtr; topPtr = newPtr; return true; } template  bool Stack ::pop(StackItem& stackTop) { if (isEmpty()) return false; else { // stack is not empty; retrieve and delete top stackTop = topPtr->item; StackNode *temp = topPtr; topPtr = topPtr->next; // return deleted node to system temp->next = nullptr; // safeguard delete temp; return true; } } template  bool Stack ::pop() { if (isEmpty()) return false; else { // stack is not empty; delete top StackNode *temp = topPtr; topPtr = topPtr->next; // return deleted node to system temp->next = nullptr; // safeguard delete temp; return true; } } template  bool Stack ::getTop(StackItem& stackTop) const { if (isEmpty()) return false; else { // stack is not empty; retrieve top stackTop = topPtr->item; return true; } } 

Write a method to remove the element at the bottom of the stack. Dont change the other elements. The method is a member of the class. Do not use other class methods in your solution.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!