Home Double Linked Queue with specific template
Reply: 0

Double Linked Queue with specific template

user2011
1#
user2011 Published in July 21, 2018, 1:52 pm

I have the intention to do a program based on a Double Linked Deque where nodes have double links and what i want to do is that each node is a "Document with name and priority" (priority = 1 insert from head, prio. = 2 insert from rear). Actually my code is like this, but i don't get everything to work with my templates as i don't know how to declare it correctly in the Node.h .

Document.h

template<class T>
class Document
{
 private:
  T name;
  T pri;

 public:
  Document(T name, T pri);
};

 template <class T> 
 Document<T>::Document(T name, T pri){
   this->name = name;
   this->pri = pri;      
}

Node.h

#include "Document.h"
template <class T> class Node{
 public:
  Node();
  Node(const T& item);
  (...other functions...)

private:
 Document<T> document;  //WHERE MY PROBLEM IS!
 Node<T>* next;
 Node<T>* previous;    
};

template <class T> 
Node<T>::Node(const T& item) {
    this->document= new Document<T>(item); //Problem with the declaration
    this->next = nullptr;
    this->previous = nullptr;
}

LinkedDeque.h

#include "Node.h"
#include "Document.h"
template <class T> class LinkedDeque {
 public:
  LinkedDeque();
  void insertFront(const T& element);
  void insertRear(const T& element);
  (... other functions ...)

private:
  Node<T>* front; //Front de la cua
  Node<T>* rear; //rear de la cua
  int num_elements;
};

template <class T>
void LinkedDeque<T>::insertFront(const T& element){

    Node<T>* aux = new Node<T>(element);

    (...rest of the function...)
}

Main.cpp

LinkedDeque<Document<string>> deque;

cin >> name >> pri;
Document<string> document(name,pri);
if (pri == "1") {
  deque.insertFront(document);
}else {
  deque.insertRear(document);
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308953 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO