Advertisement
Assa

stack.adb

Dec 31st, 2011
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 0.82 KB | None | 0 0
  1. package body is Stack
  2.   Maximum_Size : Constant := 64;
  3.   Top          : Integer  := 0;
  4.   Stack_List   : array (1 .. Maximum_Size) of Integer;
  5.  
  6.   procedure Push(Obj : in Integer) is
  7.   begin
  8.     if not Is_Full then
  9.       Top := Top + 1;
  10.       Stack_List(Top) := Obj;
  11.     end if;
  12.   end Push;
  13.  
  14.   procedure Pop(Obj : out Integer) is
  15.   begin
  16.     if Is_Empty then
  17.       Obj := 0;
  18.     else
  19.       Obj := Stack_List(Top);
  20.       Top := Top - 1;
  21.     end if
  22.   end Pop;
  23.  
  24.   function Is_Empty return Boolean is
  25.   begin
  26.     return Top = 0;
  27.   end Is_Empty;
  28.  
  29.   function Is_Full return Boolean is
  30.   begin
  31.     return Top = Maximum_Size;
  32.   end Is_Full;
  33.  
  34.   function Current_Size return Integer is
  35.   begin
  36.     return Top;
  37.   end Current_Size;
  38.  
  39.   procedure Clear is
  40.   begin
  41.     Top := 0;
  42.   end Clear;
  43.  
  44. end Stack;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement