home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 31 - Program 8
- with Text_IO;
- use Text_IO;
- with GenStack;
-
- procedure TryStak is
-
- package Int_IO is new Text_IO.Integer_IO(INTEGER);
- use Int_IO;
- package Char_Stack is new GenStack(CHARACTER);
- use Char_Stack;
-
- Example : constant STRING := "This is the first test.";
- Another : constant STRING :=
- "This is another test and this should not fit.";
-
- procedure Fill_The_Stack(Input_Line : STRING) is
- begin
- Clear_Stack;
- for Index in 1..Input_Line'LAST loop
- if Is_Full then
- Put_Line("The stack is full, no more added.");
- exit;
- else
- Push(Input_Line(Index));
- end if;
- end loop;
- end Fill_The_Stack;
-
- procedure Empty_The_Stack is
- Char : CHARACTER;
- begin
- loop
- if Is_Empty then
- New_Line;
- Put_Line("The stack is empty.");
- exit;
- else
- Pop(Char);
- Put(Char);
- end if;
- end loop;
- end Empty_The_Stack;
-
- begin
-
- Put_Line(Example);
- Fill_The_Stack(Example);
- Empty_The_Stack;
-
- New_Line;
- Put_Line(Another);
- Fill_The_Stack(Another);
- Empty_The_Stack;
-
- end TryStak;
-
-
-
-
- -- Result of execution
-
- -- This is the first test.
- -- .tset tsrif eht si sihT
- -- The stack is empty.
- --
- -- This is another test and should not fit.
- -- The stack is full, no more added.
- -- dna tset rehtona si sihT
- -- The stack is empty.
-
-