Reversable Stack Client
MC logo
 

Reversable Stack Client

Ada Code Examples


<<Reversable Stack Child Body Download Wanderer Package>>
--
-- A simple client of the Int_Stack package.
--

with Gnat.Io; use Gnat.Io;
with L_Stack.Reversable; use L_Stack; use L_Stack.Reversable;

procedure R_User is
   -- Here is a stack.  We can use the name of the private type,
   S: Int_Stack;

   -- Here's an exciting integer.
   Exciting: Integer;
begin
   -- S.Size := 5; -- This is not allowed since the type is private.

   -- Read in some integers, and push 'em
   loop
      Put("> ");
      Get(Exciting);
      exit when Exciting = -1;
      Push(S, Exciting);
   end loop;

   -- Reverse things.
   Rev_Stack(S);

   -- Pop 'em and print 'em
   while not Empty(S) loop
      Pop(S, Exciting);
      Put(Exciting);
      exit when Empty(S);
      Put(" ");
   end loop;
   New_Line;
end R_User;
<<Reversable Stack Child Body Wanderer Package>>