Question
can you help, the question is in the second capture // Array-based stack implementation template class AStack: public Stack { private: int maxSize; // Maximum
can you help, the question is in the second capture
// Array-based stack implementation
template
private:
int maxSize; // Maximum size of stack
int top; // Index for top element
Elem *listArray; // Array holding stack elements
public:
AStack(int size =DefaultListSize) // Constructor
{ maxSize = size; top = 0; listArray = new Elem[size]; }
AStack() { delete [] listArray; } // Destructor
void clear() { top = 0; } // Reinitialize
void push(const Elem& it) { // Put "it" on stack
Assert(top != maxSize, "Stack is full");
listArray[top++] = it;
}
Elem pop() { // Pop top element
Assert(top != 0, "Stack is empty");
return listArray[--top];
}
const Elem& topValue() const { // Return top element
Assert(top != 0, "Stack is empty");
return listArray[top-1];
}
int length() const { return top; } // Return length
};
Figure 4.18 Array-based stack class implementation
// Array-based stack implementation templateStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started