Queue.h 965 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace JsUtil
  7. {
  8. template <class T, class Allocator>
  9. class Queue
  10. {
  11. private:
  12. DList<T, Allocator> list;
  13. public:
  14. Queue(Allocator* alloc) : list(alloc)
  15. {
  16. }
  17. bool Empty() const
  18. {
  19. return list.Empty();
  20. }
  21. void Enqueue(const T& item)
  22. {
  23. list.Append(item);
  24. }
  25. T Dequeue()
  26. {
  27. T item = list.Head();
  28. list.RemoveHead();
  29. return item;
  30. }
  31. void Clear()
  32. {
  33. list.Clear();
  34. }
  35. };
  36. }