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

ollowing 3t ck ciass template, write the function template for the push() functi

ID: 3732553 • Letter: O

Question

ollowing 3t ck ciass template, write the function template for the push() function. Note: the stack is constructed by using an array allccated on the heap. public: bo push t? aneHIer bol po iT SpoppedItem erivate: irt maixeropreentse item in tke stack i." mMaxSize :// maatnst xcre.o the mar size :: fou!: aLiocat ea array T o will point *o ortigueus memo-y on tte heap an array) . , , / Place your function template for push below : Copies the newlten to the top of the stack Returns: te // Precondition / Eors: tuif the nenItem was placed into the contiguous menory; False otherwise tian: mTop nust already pcint to cantiguous nemory acheck tat copying the new!ten to the stack does not exceed the allocated array space; if it does, don't copy the item to the stack, and return false

Explanation / Answer

bool Stack::push(T &newItem){
   if(mSize<mMaxSize){
       mTop[mSize] = newItem;
       mSize++;
       return true;
   }
   return false;
}