具有特定模板的双链接队列
Double Linked Queue with specific template
我打算做一个基于双链接双链接的程序,其中节点有双链接,我想做的是每个节点都是一个"具有名称和优先级的文档"(优先级 = 1 个从头部插入,prio. = 2 从后面插入(。实际上我的代码是这样的,但我没有得到所有内容都可以使用我的模板,因为我不知道如何在 Node.h 中正确声明它。
文档.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;
}
节点.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...)
}
主.cpp
LinkedDeque<Document<string>> deque;
cin >> name >> pri;
Document<string> document(name,pri);
if (pri == "1") {
deque.insertFront(document);
}else {
deque.insertRear(document);
}
我看到的第一件事是您将构造函数声明为
Document(T name, T pri)
但是您正在尝试仅使用类似
this->document= new Document<T>(item)
所以我建议将名称和优先级传递给您的构造函数,这将起作用。
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- CMake-按正确顺序将项目与C运行时对象文件链接
- 从链接列表c++中删除一个项目
- 有根的二进制搜索树.保留与其父级的链接
- 读取文件的最后一行并输入到链接列表时出错
- 静态数据成员的问题-修复链接错误会导致编译器错误
- node-gyp 在 macOS 上未正确链接库
- 基于boost的程序的静态链接——zlib问题
- 我的动态链接队列在同一输出流中调用时不正确地输出三个返回函数
- 具有特定模板的双链接队列
- 在使用链接列表实施队列时,为什么插入复杂性o(1)
- 优先级队列实现为单一链接,无法更新插入的指针转换
- 队列顺序中的链接列表
- 将双重链接列表与C 中的堆栈和队列类链接
- 队列实现,带有C 中的链接列表
- C++ 链接列表队列实现和析构函数错误:"Aborted (Core Dumped)"
- 生产者-消费者队列 - std::queue 或用户编写的链接列表
- 如何在链接列表队列中将一些数据从一个节点传输到另一个节点C++
- 正在处理由双链接列表组成的学生队列
- 用优先级队列分离链接(使用std::map)