Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.2 KiB

  1. // queue standard header
  2. #ifndef _QUEUE_
  3. #define _QUEUE_
  4. #include <algorithm>
  5. #include <deque>
  6. #include <vector>
  7. #ifdef _MSC_VER
  8. #pragma pack(push,8)
  9. #endif /* _MSC_VER */
  10. _STD_BEGIN
  11. // TEMPLATE CLASS queue
  12. template<class _Ty, class _C = deque<_Ty> >
  13. class queue {
  14. public:
  15. typedef _C::allocator_type allocator_type;
  16. typedef _C::value_type value_type;
  17. typedef _C::size_type size_type;
  18. explicit queue(const allocator_type& _Al = allocator_type())
  19. : c(_Al) {}
  20. allocator_type get_allocator() const
  21. {return (c.get_allocator()); }
  22. bool empty() const
  23. {return (c.empty()); }
  24. size_type size() const
  25. {return (c.size()); }
  26. value_type& front()
  27. {return (c.front()); }
  28. const value_type& front() const
  29. {return (c.front()); }
  30. value_type& back()
  31. {return (c.back()); }
  32. const value_type& back() const
  33. {return (c.back()); }
  34. void push(const value_type& _X)
  35. {c.push_back(_X); }
  36. void pop()
  37. {c.pop_front(); }
  38. bool operator==(const queue<_Ty, _C>& _X) const
  39. {return (c == _X.c); }
  40. bool operator!=(const queue<_Ty, _C>& _X) const
  41. {return (!(*this == _X)); }
  42. bool operator<(const queue<_Ty, _C>& _X) const
  43. {return (c < _X.c); }
  44. bool operator>(const queue<_Ty, _C>& _X) const
  45. {return (_X < *this); }
  46. bool operator<=(const queue<_Ty, _C>& _X) const
  47. {return (!(_X < *this)); }
  48. bool operator>=(const queue<_Ty, _C>& _X) const
  49. {return (!(*this < _X)); }
  50. protected:
  51. _C c;
  52. };
  53. // TEMPLATE CLASS priority_queue
  54. template<class _Ty, class _C = vector<_Ty>,
  55. class _Pr = less<_C::value_type> >
  56. class priority_queue {
  57. public:
  58. typedef _C::allocator_type allocator_type;
  59. typedef _C::value_type value_type;
  60. typedef _C::size_type size_type;
  61. explicit priority_queue(const _Pr& _X = _Pr(),
  62. const allocator_type& _Al = allocator_type())
  63. : c(_Al), comp(_X) {}
  64. typedef const value_type *_It;
  65. priority_queue(_It _F, _It _L, const _Pr& _X = _Pr(),
  66. const allocator_type& _Al = allocator_type())
  67. : c(_Al), comp(_X)
  68. {for (; _F != _L; ++_F)
  69. push(*_F); }
  70. allocator_type get_allocator() const
  71. {return (c.get_allocator()); }
  72. bool empty() const
  73. {return (c.empty()); }
  74. size_type size() const
  75. {return (c.size()); }
  76. value_type& top()
  77. {return (c.front()); }
  78. const value_type& top() const
  79. {return (c.front()); }
  80. void push(const value_type& _X)
  81. {c.push_back(_X);
  82. push_heap(c.begin(), c.end(), comp); }
  83. void pop()
  84. {pop_heap(c.begin(), c.end(), comp);
  85. c.pop_back(); }
  86. protected:
  87. _C c;
  88. _Pr comp;
  89. };
  90. _STD_END
  91. #ifdef _MSC_VER
  92. #pragma pack(pop)
  93. #endif /* _MSC_VER */
  94. #endif /* _QUEUE_ */
  95. /*
  96. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  97. * Consult your license regarding permissions and restrictions.
  98. */
  99. /*
  100. * This file is derived from software bearing the following
  101. * restrictions:
  102. *
  103. * Copyright (c) 1994
  104. * Hewlett-Packard Company
  105. *
  106. * Permission to use, copy, modify, distribute and sell this
  107. * software and its documentation for any purpose is hereby
  108. * granted without fee, provided that the above copyright notice
  109. * appear in all copies and that both that copyright notice and
  110. * this permission notice appear in supporting documentation.
  111. * Hewlett-Packard Company makes no representations about the
  112. * suitability of this software for any purpose. It is provided
  113. * "as is" without express or implied warranty.
  114. */