gqueue.pp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 gqueue;
  12. interface
  13. uses gdeque;
  14. type
  15. generic TQueue<T>=class
  16. private
  17. type
  18. TContainer = specialize TDeque<T>;
  19. var
  20. FData:TContainer;
  21. public
  22. procedure Push(value:T);inline;
  23. procedure Pop();inline;
  24. function Front():T;inline;
  25. function Size():SizeUInt;inline;
  26. function IsEmpty():boolean;inline;
  27. constructor Create;
  28. destructor Destroy;override;
  29. end;
  30. implementation
  31. constructor TQueue.Create;
  32. begin
  33. FData:=TContainer.Create;
  34. end;
  35. destructor TQueue.Destroy;
  36. begin
  37. FData.Destroy;
  38. end;
  39. procedure TQueue.Push(value:T);inline;
  40. begin
  41. FData.PushBack(value);
  42. end;
  43. procedure TQueue.Pop();inline;
  44. begin
  45. FData.PopFront;
  46. end;
  47. function TQueue.Front:T;inline;
  48. begin
  49. Front:=FData.Front;
  50. end;
  51. function TQueue.Size:SizeUInt;inline;
  52. begin
  53. Size:=FData.Size;
  54. end;
  55. function TQueue.IsEmpty:boolean;inline;
  56. begin
  57. IsEmpty:=FData.IsEmpty;
  58. end;
  59. end.