home *** CD-ROM | disk | FTP | other *** search
- unit Stacks;
- { A simple exercise for the stacks unit }
-
- interface
- uses
- Classes;
-
- type
- TStack = class(TStringList)
- constructor Create;
- procedure Push(S: String);
- function Pop: String;
- function IsEmpty: Boolean;
- private
- First, Last: LongInt;
- end;
-
- implementation
-
- constructor TStack.Create;
- begin
- inherited Create;
- First := 0;
- Last := 0;
- end;
-
- procedure TStack.Push(S: String);
- begin
- Last := Add(S);
- end;
-
- function TStack.Pop: String;
- var
- S: String;
- begin
- S := Strings[First];
- inc(First);
- Pop := S;
- end;
-
- function TStack.IsEmpty: Boolean;
- begin
- if First = Last then IsEmpty := True
- else IsEmpty := False;
- end;
-
- end.
-