2020-09-30 17:12:29 +02:00

118 lines
2.9 KiB
Plaintext

// queue standard header
#ifndef _QUEUE_
#define _QUEUE_
#include <use_ansi.h>
#include <algorithm>
#include <deque>
#include <vector>
#ifdef _MSC_VER
/*
* Currently, all MS C compilers for Win32 platforms default to 8 byte
* alignment.
*/
#pragma pack(push,8)
#endif /* _MSC_VER */
// TEMPLATE CLASS queue
template<class _TYPE, class _C,
class _A>
class queue {
public:
typedef _A allocator_type;
typedef _C::value_type value_type;
typedef _C::size_type size_type;
explicit queue(const _A& _Al = _A())
: c(_Al) {}
_A get_allocator() const
{return (c.get_allocator()); }
bool empty() const
{return (c.empty()); }
size_type size() const
{return (c.size()); }
value_type& front()
{return (c.front()); }
const value_type& front() const
{return (c.front()); }
value_type& back()
{return (c.back()); }
const value_type& back() const
{return (c.back()); }
void push(const value_type& _X)
{c.push_back(_X); }
void pop()
{c.pop_front(); }
bool operator==(const queue<_TYPE, _C, _A>& _X) const
{return (c == _X.c); }
bool operator<(const queue<_TYPE, _C, _A>& _X) const
{return (c < _X.c); }
protected:
_C c;
};
// TEMPLATE CLASS priority_queue
template<class _TYPE, class _C,
class _Pr,
class _A>
class priority_queue {
public:
typedef _A allocator_type;
typedef _C::value_type value_type;
typedef _C::size_type size_type;
explicit priority_queue(const _Pr& _X = _Pr(),
const _A& _Al = _A())
: c(_Al), comp(_X) {}
typedef const value_type *_It;
priority_queue(_It _F, _It _L, const _Pr& _X = _Pr(),
const _A& _Al = _A())
: c(_Al), comp(_X)
{for (; _F != _L; ++_F)
push(*_F); }
_A get_allocator() const
{return (c.get_allocator()); }
bool empty() const
{return (c.empty()); }
size_type size() const
{return (c.size()); }
value_type& top()
{return (c.front()); }
const value_type& top() const
{return (c.front()); }
void push(const value_type& _X)
{c.push_back(_X);
push_heap(c.begin(), c.end(), comp); }
void pop()
{pop_heap(c.begin(), c.end(), comp);
c.pop_back(); }
protected:
_C c;
_Pr comp;
};
#ifdef _MSC_VER
#pragma pack(pop)
#endif /* _MSC_VER */
#endif /* _QUEUE_ */
/*
* Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
*/
/*
* This file is derived from software bearing the following
* restrictions:
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this
* software and its documentation for any purpose is hereby
* granted without fee, provided that the above copyright notice
* appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation.
* Hewlett-Packard Company makes no representations about the
* suitability of this software for any purpose. It is provided
* "as is" without express or implied warranty.
*/