Stack Fill-in (24 points) Exception class thrown by Push when stack is full. cla
ID: 3830623 • Letter: S
Question
Stack Fill-in (24 points) Exception class thrown by Push when stack is full. class class Emptys tack stack is empty. Exception class thrown by Pop and Top when Class Stack Type public 500 Stack Type(); Initializes stack array to Default class constructor. Stack Type (int maxNum) to allovied maxNum items allocates stack array elements in bool Full whether the stack is full. Function: Determines Pre: Stack has been initialized full) Post Function value (stack is bool IsEmpty() whether the stack is empty Function: Determines Pre: Stack has been initialized. empty) Post Function value (stack is void push (ItemType item); of the stack Function: Adds newItem the top initialized Pre: Stack has been exception is thrown Post If (stack is full), FullStack stack otherwise, newItem is at the top of the void Pop top item from the stack. Function Removes Pre: Stack has been initialized. is Post: If (stack is empty), exception stack. otherwise top element has been removed from Item Type Top top item on the stack Function: Returns a copy of Pre: Stack has been initialized. thrown Post: If (stack is empty), exception is stack otherwise top element has been removed from Top element index. An empty stack is indicated by 0 Max number of elements that can be stored in stack private: int top; int max Items; of the dynamically allocated array ItemType items; The addressExplanation / Answer
StackType::StackType()
{
maxItems = 500;
top = 0;
items = new ItemType[maxItems];
}
bool StackType::IsEmpty() const
{
return (top == 0);
}
void StackType::Pop()
{
if(IsEmpty()) {
throw EmptyStack();
}
top--;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.