title: Linking Doubly linked list with Stack and Queue classes in C++
body: <p>so I have an assignment where I need to create a doubly linked list and then create a stack and queue class and inherit from the <code>linkedlist</code> class in order to create an <code>RPN calculator</code>. So far I have created my doubly linkedlist class and the other to classes. However, I am having trouble understanding how I will inherit and use the linked list class with the stack and queue. I will provide what I have so far. </p>
  
  <p>I have gone to tutoring and have not had much help so I thought I would look for some extra help, do not want homework done for me but to just be pointed in the right direction.</p>
  
  <p><em>Stack.h</em></p>
  
  <pre><code>using std::iterator;
  using std::vector;
  using std::string;
  
  template&lt;class T&gt;
  class Stack : public vector&lt;T&gt;
  {
  private:
      T getElement(bool erase);
      typename std::vector&lt;T&gt; ::iterator pEnd;
      T top;
  
  public:
      Stack();
      T pop();
      T peek();
      void push(T elem);
  };
  
  
  
  template&lt;class T&gt;
  Stack&lt;T&gt;::Stack()
  {
  
  }
  
  template&lt;class T&gt;
  void Stack&lt;T&gt;::push(T elem)
  {
      this-&gt;push_back(elem);
  
  }
  
  template&lt;class T&gt;
  T Stack&lt;T&gt;::peek()
  {
      return this-&gt;getElement(false);
  }
  
  template&lt;class T&gt;
  T Stack&lt;T&gt;::pop()
  {
      return this-&gt;getElement(true);
  }
  
  template&lt;class T&gt;
  T Stack&lt;T&gt;::getElement(bool erase)
  {
      this-&gt;pEnd = this-&gt;end() - 1;
      T tmp;
      if (this-&gt;size() &gt; 0)
      {
          tmp = *this-&gt;pEnd;
          if (erase) {
              this-&gt;erase(pEnd);
          }
      }
  
      return tmp;
  
  }
  </code></pre>
  
  <p><em>Queue.h</em></p>
  
  <pre><code>using namespace std;
  
  class Queue
  {
  
  private:
      int items[MAXQUEUE];
      int head;
      int tail;
  
  public:
      Queue();
      bool isEmpty();
      bool isFull();
      bool enqueue(int item);
      int dequeue();
      int peek();
  };
  
  
  
  Queue::Queue()
      :head(QEMPTY), tail(QEMPTY)
  {
  
  }
  
  bool Queue::isEmpty()
  {
      return this-&gt;head == this-&gt;tail;
  
  }
  
  bool Queue::isFull()
  {
  
      return this-&gt;tail == MAXQUEUE;
  }
  
  bool Queue::enqueue(int item)
  {
      if (this-&gt;isFull())
          return false;
  
      this-&gt;items[this-&gt;tail] = item;
      tail = (tail + 1) % MAXQUEUE;
      return true;
  
  }
  
  int Queue::dequeue()
  {
      if (this-&gt;isEmpty())
          return EMPTY;
  
      int item = this-&gt;items[head];
      this-&gt;head = (this-&gt;head + 1) % MAXQUEUE;
      return item;
  }
  
  int Queue::peek() {
  
      return this-&gt;tail;
  }
  </code></pre>
  
  <p><em>doublylinkedlist.h</em></p>
  
  <pre><code> using std::iterator;
  using std::vector;
  using std::string;
  
  
  
  /*START OF NODE CLASS*/
  /*---------------------------------------------*/
  template&lt;class T&gt;
  struct Node
  {
  
      T Data;
      T Search;
      T value;
      Node&lt;T&gt;*Next;
      Node&lt;T&gt;*Prev;
  };
  
  
  template&lt;class T&gt;
  class LinkedList
  {
  private:
      Node&lt;T&gt; *Head;
  public:
      LinkedList();
      void addNode(T Data);
      void deleteNode(T Search);
      void insert(T Search, T value);
      void printListBackwards();
      void printListForwards();
  };
  template&lt;class T&gt;
  LinkedList&lt;T&gt;::LinkedList()
  {
      this-&gt;Head = NULL;
  
  }
  
  template&lt;class T&gt;
  void LinkedList&lt;T&gt;::addNode(T data)
  {
  
      if (Head == NULL)
      {
          Head = new Node&lt;T&gt;;
          Head-&gt;Data = data;
          Head-&gt;Next = NULL;
          Head-&gt;Prev = NULL;
  
      }
      else
      {
          Node&lt;T&gt;*p = this-&gt;Head;
  
  
          while (p-&gt;Next != NULL)
  
              p = p-&gt;Next;
  
          Node&lt;T&gt;*n = new Node&lt;T&gt;;
          n-&gt;Data = data;
          n-&gt;Next = NULL;
          p-&gt;Next = n;
          n-&gt;Prev = p;
      }
  
  
  }
  
  template&lt;class T&gt;
  void LinkedList&lt;T&gt;::insert(T Search, T value)
  {
  
      Node *p = Head;
      while (p-&gt;Data != Search)
      {
          p = p-&gt;Next;
      }
  
      Node *n = new Node;
      n-&gt;Data = value;
      n-&gt;Next = p-&gt;Next;
      p-&gt;Next = n;
  
  }
  
  template&lt;class T&gt;
  void LinkedList&lt;T&gt;::deleteNode(T Search)
  {
      Node *p = Head;
      while (p-&gt;Next-&gt;Data != Search)
      {
          p = p-&gt;Next;
      }
  
      Node *delPtr = p-&gt;Next;
      p-&gt;Next = p-&gt;Next-&gt;Next;
  
      delete delPtr;
  }
  
  template&lt;class T&gt;
  void LinkedList&lt;T&gt;::printListBackwards()
  {
      Node&lt;T&gt; *p = Head;
  
      while (p-&gt;Next != NULL)
      {
  
          p = p-&gt;Next;
      }
      while (p != NULL)
      {
          cout &lt;&lt; p-&gt;Data&lt;&lt; endl;
          p = p-&gt;Prev;
      }
  }
  
  template&lt;class T&gt;
  void LinkedList&lt;T&gt;::printListForwards()
  {
  
      Node&lt;T&gt; *p = Head;
      while (p != NULL)
      {
          cout &lt;&lt; p-&gt;Data &lt;&lt; endl;
          p = p-&gt;Next;
      }
  }
  </code></pre>