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

ll File: StacksArrays.h Header file to implement a stack using arrays N Class St

ID: 3725884 • Letter: L

Question

ll File: StacksArrays.h Header file to implement a stack using arrays N Class StackClass class StackClass private int "data, nt size nt top public W Class constructor -StackClasso: void PushData int int PopData 0 // Class destructor If Function to push data into the stack r Function to pop data from the stack f File to implement a stack using arrays Fincude "StacksArrays h" N StackClass constructor StackClass StackClass (int sz) size (sz), top(-1) data·new int(sz); W StackClass destructor StackClass-StackClass 0 deletel data size 0; N Function: PushData W Function to push data items into the stack void StackClass PushData (int num) r Increment the top counter if (top size) Il Check if the size of stack is equal to top throw Stack Ful Can't add datain dataftop) num; " Push the num at the top of the stack N Function: PopData W Function to pop data items from the stack int StackClass: PopData 0 W Check if the stack is empty throw "Stack Empty return //Pop the data from the top of the stack W File: StacksArraysMain.cpp

Explanation / Answer

Answer is as follows :

1) StacksArrays.h file

We know that constructor name is same as Class name, so class name is StackClass and it has also a variable i.e. of integer part, so constructor name is as follows :

StackClass(int sz);

2) Function Push Data :

We have to increment top variable here.So result is

top++ or we can also write top = top + 1

3) Function Pop Data:

If the stack is empty than we check that top of stack is less than 0, so the fill up has

if(top < 0), if this is true or top is less than 0 means -1 than stack is empty.

if it is not true than it return the top by -1

So next fill up is return top--

if there is any query or missing part than please ask in comments......