//
// Adaptor class providing for a single type that can act as both
// a stack and a queue
// File: BinSearchTree/queStack.h
//
// Examples: stack_queue<list<int> >
//           stack_queue<deque<double> >  doesn't work under gcc 2.7.2
//
// -------------------------------------------------------------


#ifndef STACK_QUEUE_H
#define STACK_QUEUE_H

#include <list.h>
#include <deque.h>

// -------------------------------------------------------------

template <class Container>
class stack_queue
{
public:
    typedef Container::value_type value_type;
    typedef Container::size_type size_type;
protected:
    Container c;
public:
    void push   (const value_type& x) {c.push_back(x);} // insert at the beginning
    void append (const value_type& x) {c.push_front(x);}// append at the end of list
    value_type pop (void) // remove first element
       { value_type x; x = c.back();
         c.pop_back(); return x;
       }


    bool isEmpty (void) { return c.empty() ; }
    void makeEmpty (void) { c.erase(c.begin(), c.end()); }
};

// -------------------------------------------------------------

#endif
