📄 linkedqueue.cpp
字号:
// LinkedQueue.cpp: implementation of the LinkedQueue class.
//
//////////////////////////////////////////////////////////////////////
#include "LinkedQueue.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//清空队列
template<class T>
void LinkedQueue<T>::makeEmpty()
{
LinkNode<T>*p;
while(front!=NULL)
{
p=front;
front=front->link;
delete p;
}
}
//入队
template<class T>
bool LinkedQueue<T>::EnQueue(const T&x)
{
if(front==NULL)
{
front=rear=new LinkNode<T>(x);
if(front==NULL)
return false;
}
else
{
rear->link=new LinkNode<T>(x);
if(rear->link==NULL)return false;
rear=rear->link;
}
return true;
}
//出队
template<class T>
bool LinkedQueue<T>::DeQueue(T&x)
{
if(IsEmpty()==true)return false;
LinkNode<T>*p=front;
x=front->data;
front=front->link;
delete p;
return true;
}
//得首结点
template<class T>
bool LinkedQueue<T>::getFront(T&x)const
{
if(IsEmpty()==true)
return false;
x=front->data;
return true;
}
//得结点数
template<class T>
int LinkedQueue<T>::getSize()const
{
LinkNode<T>*p=front;
int k=0;
while(p!=NULL)
{
p=p->link;
k++;
}
return k;
}
//输出重载
template<class T>
ostream&operator<<(ostream&os,LinkedQueue<T>&Q)
{
os<<"队列中元素个数有"<<Q.getSize()<<endl;
LinkNode<T>*p=Q.front;
int i=0;
while(p!=NULL)
{
os<<++i<<":"<<p->data<<endl;
p=p->link;
}
return os;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -