诸位高人这个程序那错了(循环队列)
各位高人这个程序那错了(循环队列)
#include<iostream>
using namespace std;
template <class T>
struct Node
{
T data;
Node<T> *next; //此处<T>也可以省略
};
template <class T>
class LinkQueue
{
public:
LinkQueue(); //构造函数,初始化一个空的链队列
~LinkQueue( ); //析构函数,释放链队列中各结点的存储空间
void EnQueue(); //将元素x入队
T DeQueue( ); //将队头元素出队
T GetQueue( ) {if (front!=rear) return front->next->data;} //取链队列的队头元素
bool Empty( )
{
if(front==rear)
return 0;
else
return 1;
}
//判断链队列是否为空
private:
Node<T> *front, *rear; //队头和队尾指针,分别指向头结点和终端结点
};
template <class T>
T LinkQueue<T>::DeQueue( )
{
if (rear==front) throw "下溢";
Node<T>*p=front->next; T x=p->data; //暂存队头元素
front->next=p->next; //将队头元素所在结点摘链
if (p->next==NULL) rear=front; //判断出队前队列长度是否为1
delete p;
return x;
}
template <class T>
LinkQueue<T>::LinkQueue( )
{
Node <T>*s=new Node<T>;
s->next=NULL; //创建一个头结点s
front=rear=s; //将队头指针和队尾指针都指向头结点s
}
template <class T>
void LinkQueue<T>::EnQueue()
{
T x;
cout<<"请输入要插入的队列的值,按ctrl Z结束"<<endl;
while(cin>>x)
{
Node<T>*s=new Node<T>; s->data=x; //申请一个数据域为x的结点s
s->next=NULL;
rear->next=s; //将结点s插入到队尾
rear=s;
}
}
int main()
{
LinkQueue<int>Q;
Q.EnQueue();
while(Q.Empty( ))
cout<< Q.DeQueue()<<" ";
return 0;
}
错误:循环队列.obj : error LNK2001: unresolved external symbol "public: __thiscall LinkQueue<int>::~LinkQueue<int>(void)" (??1?$LinkQueue@H@@QAE@XZ)
Debug/循环队列.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
谢谢了
------解决方案--------------------
~LinkQueue( );
析构函数没写实现,只写了声明。
#include<iostream>
using namespace std;
template <class T>
struct Node
{
T data;
Node<T> *next; //此处<T>也可以省略
};
template <class T>
class LinkQueue
{
public:
LinkQueue(); //构造函数,初始化一个空的链队列
~LinkQueue( ); //析构函数,释放链队列中各结点的存储空间
void EnQueue(); //将元素x入队
T DeQueue( ); //将队头元素出队
T GetQueue( ) {if (front!=rear) return front->next->data;} //取链队列的队头元素
bool Empty( )
{
if(front==rear)
return 0;
else
return 1;
}
//判断链队列是否为空
private:
Node<T> *front, *rear; //队头和队尾指针,分别指向头结点和终端结点
};
template <class T>
T LinkQueue<T>::DeQueue( )
{
if (rear==front) throw "下溢";
Node<T>*p=front->next; T x=p->data; //暂存队头元素
front->next=p->next; //将队头元素所在结点摘链
if (p->next==NULL) rear=front; //判断出队前队列长度是否为1
delete p;
return x;
}
template <class T>
LinkQueue<T>::LinkQueue( )
{
Node <T>*s=new Node<T>;
s->next=NULL; //创建一个头结点s
front=rear=s; //将队头指针和队尾指针都指向头结点s
}
template <class T>
void LinkQueue<T>::EnQueue()
{
T x;
cout<<"请输入要插入的队列的值,按ctrl Z结束"<<endl;
while(cin>>x)
{
Node<T>*s=new Node<T>; s->data=x; //申请一个数据域为x的结点s
s->next=NULL;
rear->next=s; //将结点s插入到队尾
rear=s;
}
}
int main()
{
LinkQueue<int>Q;
Q.EnQueue();
while(Q.Empty( ))
cout<< Q.DeQueue()<<" ";
return 0;
}
错误:循环队列.obj : error LNK2001: unresolved external symbol "public: __thiscall LinkQueue<int>::~LinkQueue<int>(void)" (??1?$LinkQueue@H@@QAE@XZ)
Debug/循环队列.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
谢谢了
------解决方案--------------------
~LinkQueue( );
析构函数没写实现,只写了声明。