/* * File: stack.cpp * Author: David Metcalf * Date: February 2001 * Class: CS112 * Assignment: Implementation of stack module * ----------------------------------------------------- */ #include #include "stack.h" /* declarations of public functions */ /*------------------------------------------------------------*/ /* Stack::Stack constructor * creates stack and initializes it */ Stack::Stack() { count=0; } /*------------------------------------------------------------*/ /* Stack::Init: * Usage: stack.Init(); * Initializes a stack. */ bool Stack::Init() { count=0; return true; } /*------------------------------------------------------------*/ /* Stack::IsEmpty: * Usage: if(stack.IsEmpty()) {...} * checks whether a stack is empty. */ bool Stack::IsEmpty() { return(count==0); } /*------------------------------------------------------------*/ /* Stack::IsFull: * Usage: if(stack.IsFull()) {...} * checks whether a stack is full. */ bool Stack::IsFull() { return(count==MAXSTACKSIZE); } /*------------------------------------------------------------*/ /* Stack::Push: * Usage: flag= stack.Push(item); * pushes item onto stack. * returns true if successful. */ bool Stack::Push(ItemType Item) { if (IsFull()) { return(false); } data[count]=Item; count++; return true; } /*------------------------------------------------------------*/ /* Stack::Pop: * Usage: flag= stack.Pop(Item); * Pops top item off stack. * Sets Item equal to the popped element. */ { You need to implement this method. } /* ----------- END OF FILE: stack.cpp ---------- */