home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / queue < prev    next >
Text File  |  1998-06-16  |  3KB  |  125 lines

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