From 357744cd54478d5d74cb52cd1459eb7c26192abd Mon Sep 17 00:00:00 2001 From: phil Date: Sat, 9 Mar 1996 00:00:51 +0000 Subject: Import of libg++-2.7.1. --- gnu/lib/libg++/libstdc++/stl/stack.h | 120 +++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 gnu/lib/libg++/libstdc++/stl/stack.h (limited to 'gnu/lib/libg++/libstdc++/stl/stack.h') diff --git a/gnu/lib/libg++/libstdc++/stl/stack.h b/gnu/lib/libg++/libstdc++/stl/stack.h new file mode 100644 index 00000000000..83a59a4c2af --- /dev/null +++ b/gnu/lib/libg++/libstdc++/stl/stack.h @@ -0,0 +1,120 @@ +/* + * + * 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. + * + */ + +#ifndef STACK_H +#define STACK_H + +#ifndef __GNUG__ +#include +#endif +#include + +template +class stack { +friend bool operator==(const stack& x, const stack& y); +friend bool operator<(const stack& x, const stack& y); +public: + typedef Container::value_type value_type; + typedef Container::size_type size_type; +protected: + Container c; +public: + bool empty() const { return c.empty(); } + size_type size() const { return c.size(); } + value_type& top() { return c.back(); } + const value_type& top() const { return c.back(); } + void push(const value_type& x) { c.push_back(x); } + void pop() { c.pop_back(); } +}; + +template +bool operator==(const stack& x, const stack& y) { + return x.c == y.c; +} + +template +bool operator<(const stack& x, const stack& y) { + return x.c < y.c; +} + +template +class queue { +friend bool operator==(const queue& x, const queue& y); +friend bool operator<(const queue& x, const queue& y); +public: + typedef Container::value_type value_type; + typedef Container::size_type size_type; +protected: + Container c; +public: + 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(); } +}; + +template +bool operator==(const queue& x, const queue& y) { + return x.c == y.c; +} + +template +bool operator<(const queue& x, const queue& y) { + return x.c < y.c; +} + +template +// Compare = less > +class priority_queue { +public: + typedef Container::value_type value_type; + typedef Container::size_type size_type; +protected: + Container c; + Compare comp; +public: + priority_queue(const Compare& x = Compare()) : c(), comp(x) {} + priority_queue(const value_type* first, const value_type* last, + const Compare& x = Compare()) : c(first, last), comp(x) { + make_heap(c.begin(), c.end(), comp); + } +/* + template + priority_queue(InputIterator first, InputIterator last, + const Compare& x = Compare()) : c(first, last), comp(x) { + make_heap(c.begin(), c.end(), comp); + } +*/ + 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(); + } +}; + +// no equality is provided + +#endif -- cgit