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.

129 lines
3.4 KiB

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