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;
- Implement the constructor and the display function of the array-based stack class below. (15 Points)
template
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
Get step-by-step solutions from verified subject matter experts
