| Line | |
|---|
| 1 | unit GenericStack;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | GenericList;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 11 | TGStack<T> = class
|
|---|
| 12 | private
|
|---|
| 13 | FList: TGList<T>;
|
|---|
| 14 | public
|
|---|
| 15 | procedure Push(Value: T);
|
|---|
| 16 | function Pop: T;
|
|---|
| 17 | constructor Create;
|
|---|
| 18 | destructor Destroy; override;
|
|---|
| 19 | property List: TGList<T> read FList;
|
|---|
| 20 | end;
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | implementation
|
|---|
| 24 |
|
|---|
| 25 | { TGStack }
|
|---|
| 26 |
|
|---|
| 27 | procedure TGStack<T>.Push(Value: T);
|
|---|
| 28 | begin
|
|---|
| 29 | FList.Add(Value);
|
|---|
| 30 | end;
|
|---|
| 31 |
|
|---|
| 32 | function TGStack<T>.Pop: T;
|
|---|
| 33 | begin
|
|---|
| 34 | Result := FList.Extract(FList.Last);
|
|---|
| 35 | end;
|
|---|
| 36 |
|
|---|
| 37 | constructor TGStack<T>.Create;
|
|---|
| 38 | begin
|
|---|
| 39 | FList := TGList<T>.Create;
|
|---|
| 40 | end;
|
|---|
| 41 |
|
|---|
| 42 | destructor TGStack<T>.Destroy;
|
|---|
| 43 | begin
|
|---|
| 44 | FList.Free;
|
|---|
| 45 | inherited Destroy;
|
|---|
| 46 | end;
|
|---|
| 47 |
|
|---|
| 48 | end.
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.