Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

13. (8 pts) Given the following Stack class template, write the function templat

ID: 3730245 • Letter: 1

Question

13. (8 pts) Given the following Stack class template, write the function template for the pop () function. Note: the stack is constructed by using an array allocated on the heap. template class Stack public: Stack (int newSize = 0); Stack) bool push (T &newItem;) ; bool pop(T &poppedItem;) bool peek (T &item;) bool isEmpty)i private: int mSize: / represents the number of items in the stack int mMaxSize: must not exceed the max size of our aliocated array T mTop; // will point to contiguous memory on the heap (an array) // Place your function template for pop () below. // In this implementation you will apply defensive design. You must check to /I see if the stack is empty or not before you pop. Places the popped item in // the parameter referred to as "poppedltem". Returns true if the item was popped; false

Explanation / Answer

bool Stack::pop(T &poppedItem){
   if(mSize>0){
       poppedItem = mTop[mSize-1];
       mSize--;
       return true;
   }
   return false;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote