From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,413164aa26adbd93,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-02 10:37:28 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc03.POSTED!not-for-mail From: Stapler Subject: Int_Stack rewritten. Newsgroups: comp.lang.ada User-Agent: Pan/0.11.4 (Unix) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Comment-To: ALL Message-ID: NNTP-Posting-Host: 12.241.145.39 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc03 1038854247 12.241.145.39 (Mon, 02 Dec 2002 18:37:27 GMT) NNTP-Posting-Date: Mon, 02 Dec 2002 18:37:27 GMT Organization: AT&T Broadband Date: Mon, 02 Dec 2002 18:37:27 GMT Xref: archiver1.google.com comp.lang.ada:31353 Date: 2002-12-02T18:37:27+00:00 List-Id: As per the suggestions, I've rewritten my simple Int_Stack package. Hope it looks better. package int_stack is pragma Pure(int_stack); Stack_Overflow : Exception; Stack_Underflow : Exception; -- As far as I can tell these procedures are squared away. -- 12/02/02 type Int_Stack(Size : Natural) is limited private; procedure Push(The_Stack : in out Int_Stack; X : in Integer); procedure Pop(The_Stack : in out Int_Stack; X : out Integer); -- These functions and procedures are new and untested. function Is_Empty(The_Stack : in Int_Stack) return Boolean; function Is_Full(The_Stack : in Int_Stack) return Boolean; function Length_Of(The_Stack : in Int_Stack) return Natural; function Sum_Of(The_Stack : in Int_Stack) return Integer; -- I will add more functions and procedures as soon as I'm sure -- this basic package isn't hosed. private type Integer_Array is array(Positive range <>) of Integer; type Int_Stack(Size : Natural) is limited record Elements : Integer_array(1..Size); Top : Natural := 1; end record; end int_stack; package body int_stack is procedure Push(The_Stack : in out Int_Stack; X : in Integer) is begin if The_Stack.Top > The_Stack.Size then raise Stack_Overflow; end if; The_Stack.Elements(The_Stack.Top) := X; if The_Stack.Top < The_Stack.Size then The_Stack.Top := The_Stack.Top + 1; end if; end Push; procedure Pop(The_Stack : in out Int_Stack; X : out Integer) is begin If The_Stack.Top < 1 then raise Stack_Underflow; end if; X := The_Stack.Elements(The_Stack.Top); if The_Stack.Top > 1 then The_Stack.Top := The_Stack.Top - 1; end if; end Pop; function Is_Empty(The_Stack : in Int_stack) return Boolean is begin if The_Stack.Top = The_Stack.Elements'First then return True; else return False; end if; end Is_Empty; function Is_Full(The_Stack : in Int_Stack) return Boolean is begin if The_Stack.Top = The_Stack.Elements'Last then return True; else return False; end if; end Is_Full; function Length_Of(The_Stack : in Int_Stack) return Natural is Length : Natural; begin -- This entire function seems somewhat rendundant -- considering the "Length" attribute. But it's -- being included as suggested Length := The_Stack.Elements'Length; return Length; end Length_Of; function Sum_Of(The_Stack : in Int_Stack) return Integer is The_Sum : Integer := 0; begin for J in 1..The_Stack.Top loop The_Sum := The_Sum + The_Stack.Elements(J); end loop; return The_Sum; end Sum_Of; end int_stack; I hope this one looks better. So, have I improved somewhat? Heh. Thanks for your patience, and try not to laugh to hard. Heh. Stapler