home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / trystak.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.5 KB  |  71 lines

  1.                                        -- Chapter 16 - Program 2
  2. with Text_IO;
  3. use Text_IO;
  4. with CharStak;
  5. use CharStak;
  6.  
  7. procedure TryStak is
  8.  
  9.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  10.    use Int_IO;
  11.  
  12.    Example : constant STRING := "This is the first test.";
  13.    Another : constant STRING :=
  14.                   "This is another test and this should not fit.";
  15.  
  16.    procedure Fill_The_Stack(Input_Line : STRING) is
  17.    begin
  18.       Clear_Stack;
  19.       for Index in 1..Input_Line'LAST loop
  20.          if Is_Full then
  21.             Put_Line("The stack is full, no more added.");
  22.             exit;
  23.          else
  24.             Push(Input_Line(Index));
  25.          end if;
  26.       end loop;
  27.    end Fill_The_Stack;
  28.  
  29.    procedure Empty_The_Stack is
  30.    Char : CHARACTER;
  31.    begin
  32.       loop
  33.          if Is_Empty then
  34.             New_Line;
  35.             Put_Line("The stack is empty.");
  36.             exit;
  37.          else
  38.             Pop(Char);
  39.             Put(Char);
  40.          end if;
  41.       end loop;
  42.    end Empty_The_Stack;
  43.  
  44. begin
  45.  
  46.    Put_Line(Example);
  47.    Fill_The_Stack(Example);
  48.    Empty_The_Stack;
  49.  
  50.    New_Line;
  51.    Put_Line(Another);
  52.    Fill_The_Stack(Another);
  53.    Empty_The_Stack;
  54.  
  55. end TryStak;
  56.  
  57.  
  58.  
  59.  
  60. -- Result of execution
  61.  
  62. -- This is the first test.
  63. -- .tset tsrif eht si sihT
  64. -- The stack is empty.
  65. --
  66. -- This is another test and should not fit.
  67. -- The stack is full, no more added.
  68. --  dna tset rehtona si sihT
  69. -- The stack is empty.
  70.  
  71.