gstack.pp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. {
  2. This file is part of the Free Pascal FCL library.
  3. BSD parts (c) 2011 Vlado Boza
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY;without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {$mode objfpc}
  11. unit gstack;
  12. interface
  13. uses gvector;
  14. type
  15. generic TStack<T>=class
  16. private
  17. type TContainer= specialize TVector<T>;
  18. var FData:TContainer;
  19. public
  20. Procedure Clear;
  21. procedure Push(x:T);inline;
  22. procedure Pop();inline;
  23. function Top():T;inline;
  24. function Size():longint;inline;
  25. function IsEmpty():boolean;inline;
  26. constructor Create;
  27. destructor Destroy;override;
  28. end;
  29. implementation
  30. constructor TStack.Create;
  31. begin
  32. FData:=TContainer.Create;
  33. end;
  34. Procedure TStack.Clear;
  35. begin
  36. FData.Clear;
  37. end;
  38. destructor TStack.Destroy;
  39. begin
  40. FData.Destroy;
  41. end;
  42. procedure TStack.Push(x:T);inline;
  43. begin
  44. FData.PushBack(x);
  45. end;
  46. procedure TStack.Pop;inline;
  47. begin
  48. FData.PopBack;
  49. end;
  50. function TStack.Top:T;inline;
  51. begin
  52. Top:=FData.Back;
  53. end;
  54. function TStack.Size:longint;inline;
  55. begin
  56. Size:=FData.Size;
  57. end;
  58. function TStack.IsEmpty:boolean;inline;
  59. begin
  60. IsEmpty:=FData.IsEmpty;
  61. end;
  62. end.