/* * queue_stack_list.cpp * * Created on: 20.11.2015 г. * Author: trifon */ #include using namespace std; #include "linked_list.cpp" #include "lqueue.cpp" #include "lstack.cpp" template class Object { public: // включване virtual bool insert(T const&) = 0; // изключване virtual bool remove(T&) = 0; // извеждане virtual void print(ostream& os) const = 0; virtual ~Object() {} }; template class StackObject : public Object, private LinkedStack { public: // включване bool insert(T const& x) { LinkedStack::push(x); return true; } // изключване bool remove(T& x) { if (LinkedStack::empty()) return false; x = LinkedStack::pop(); return true; } // извеждане void print(ostream& os) const { os << *this; } }; template class QueueObject : public Object, private LinkedQueue { public: // включване bool insert(T const& x) { LinkedQueue::enqueue(x); return true; } // изключване bool remove(T& x) { if (LinkedQueue::empty()) return false; x = LinkedQueue::dequeue(); return true; } // извеждане void print(ostream& os) const { os << *this; } }; template //using QueueStackList = LinkedList*>; class QueueStackList : public LinkedList*> { public: ~QueueStackList() { for(LinkedListIterator*> it = this->begin(); it; ++it) delete *it; } }; /* template ostream& operator<<(ostream& os, QueueStackList const& qsl) { for(LinkedListIterator*> it = qsl.begin(); it; ++it) (*it)->print(os); return os << endl; } */ template ostream& operator<<(ostream& os, Object* o) { o->print(os); return os; }