-- Assignment : Homework due Sept. 21st, 2006 -- Programmer : Daniel Koestler -- Course : CS 240 -- Date : Sept. 20th, 2006 -- Compiler : gcc with gnat -- Professor : Elizabeth Adams -- Filename : stack.adb -- Executable : -- Version : 0.2 -- Purpose: To implement the stack data type as dicussed in class. -- Input : none -- Output -- To Screen : Messages in the event of an error pushing or -- popping from a full or empty stack, respectively. -- Modifications: -- -- Version 0.2 : A typo fixed in the peek declaration! with ada.text_io; -- use ada.text_io; package body stack is -- pre-Condition : theStack exists and theValue exists -- post-Condition : theValue has been added to the stack -- raises error if theStack is full procedure push ( theStack : in out stackType; theValue : in Integer ) is begin if not (theStack.top = theStack.MAXDATA ) then theStack.top := theStack.top + 1; theStack.aStack(theStack.top) := theValue; else ada.text_io.put_line ( "A number could not be added to the stack, because it is full."); end if; end push; procedure pop ( theStack : in out stackType; theValue : out Integer ) is begin if ( theStack.top > 0 ) then theValue := theStack.aStack(theStack.top); theStack.top := theStack.top - 1; else ada.text_io.put_line ("A number could not be popped off of the stack, because it is empty."); end if; end pop; procedure peek ( theStack : in stackType; theValue : in out Integer ) is begin if ( theStack.top /= 0 ) then theValue := theStack.aStack(theStack.top); else ada.text_io.put_line ("A number could not be peeked at, because the stack is empty."); end if; end peek; procedure makeEmpty ( theStack : in out stackType ) is begin theStack.top := 0; end makeEmpty; function isFull ( theStack : in stackType ) return boolean is result : boolean; begin result := false; if ( theStack.top > theStack.MAXDATA ) then result := true; end if; return result; end isFull; function isEmpty ( theStack : in stackType ) return boolean is result : boolean; begin result := false; if ( theStack.top = 0 ) then result := true; end if; return result; end isEmpty; end stack;