我正在尝试使用双链表实现DEQUE。
DEQUE.h
using namespace std;
template <typename T>
class Node{
Node(const T& data):data(data), next(0), prev(0) {}
public:
Node* next;
Node* prev;
T data;
};
template <typename T>
class DEQUE
{
//interface
};
DEQUE.cpp
template <class T>
void DEQUE< T > ::AddFirst(T t){
Node<T>* temp = new Node(t);
if ( counter != 0 ) {
temp->next = head;
temp->prev = 0 ;
head->prev = temp;
head =temp;
counter++;
}
else{
head = temp;
tail = temp;
temp->next = 0;
temp->prev = 0;
counter++;
}
};
我在行上出现“节点”错误之前就得到了预期的类型说明符
Node<T>* temp = new Node(t);
我在这里做错了什么?我在这里先向您的帮助表示感谢。
创建以下实例时,您忘记了类型Node
:
Node<T>* temp = new Node<T>(t);
^^^ missing.
Node
不会自动假定用于创建的实例的类型与用于的类型相同DEQUE
。您必须明确指定它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句