/* Filename: ArrStack.cpp Programmer: Br. David Carlson Date: August 8, 1998 Modified: April 23, 1999 to use an array-based implementation. Modified: June 7, 1999 to use exceptions. Modified: June 26, 2000 This file implements the functions of the ArrStackClass found in ArrStack.h. */ #include "arrstack.h" /* Given: Nothing. Task: This is a constructor. It creates and initializes a new stack to empty. Return: Nothing other than the newly created object. */ ArrStackClass::ArrStackClass(void) { Top = -1; } /* Given: Nothing (other than the implicit ArrStackClass object). Task: To check whether this object is empty. Return: true if it is empty, false otherwise. */ bool ArrStackClass::Empty(void) const { if (Top < 0) return true; else return false; } /* Given: Item A data item. Task: To push item onto the stack (the implicit object). Throws an int exception if no room to push. Return: Nothing directly, but the implicit object is modified. */ void ArrStackClass::Push(const ItemType & Item) { Top++; if (Top >= StackMax) { Top--; throw Top; } else Info[Top] = Item; // assumes = works for ItemType } /* Given: Nothing. Task: To pop the top item from the stack (the implicit object). Throws an int exception if nothing can be popped. Return: Item The item popped from the stack. */ void ArrStackClass::Pop(ItemType & Item) { if (Top < 0) throw Top; else { Item = Info[Top]; // assumes that = works on this type Top--; } }