Question: Implement the constructor and the display function of the array-based stack class below. (15 Points) template class myStack{ T *ptr; // storage body int size;

  1. Implement the constructor and the display function of the array-based stack class below. (15 Points)

template class myStack{

T *ptr; // storage body

int size; // storage size

int top; // top position

public:

myStack(int); // constructor

~myStack(){free(ptr);} // destructor

bool empty(){return top==-1;} // empty or not

bool full(){return top==size-1;} // full or not

int hold(){return top+1;} // number of items hold

void push(T v){ptr[++top]=v;} // put an item on top

T pop(){return ptr[top--];} // take an item from top

void display(int); // display, m items per line

};

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!