关于Node.h,请参考LinkStack

 #include"Node.h"
template<typename ElemType>
class LinkQueue
{
protected:
Node<ElemType> *front,*rear;
int count;
public:
LinkQueue();
virtual ~LinkQueue();
int Length()const;
bool Empty()const;
void Clear();
bool Inqueue(const ElemType &e);
bool Outqueue(ElemType &e);
bool GetHead(ElemType &e) const;
void Traverse(void(*visit)(const ElemType &))const;
LinkQueue(const LinkQueue<ElemType> &copy);
LinkQueue<ElemType> &operator=(const LinkQueue<ElemType> &copy);
};
template<typename ElemType>
//构造一个空队列;
LinkQueue<ElemType>::LinkQueue()
{
front=rear=new Node<ElemType>;
count=;
}
template<typename ElemType>
//虚虚构函数
LinkQueue<ElemType>::~LinkQueue()
{
Clear();
}
template<typename ElemType>
//返回队列长度
int LinkQueue<ElemType>::Length()const
{
return count;
}
template<typename ElemType>
//判断队列为空
bool LinkQueue<ElemType>::Empty()const
{
return count==;
}
template<typename ElemType>
//清除队列
void LinkQueue<ElemType>::Clear()
{
ElemType tmpElem;
while(!Empty())
Outqueue(tmpElem);
}
template<typename ElemType>
//队尾进队
bool LinkQueue<ElemType>::Inqueue(const ElemType &e)
{
Node<ElemType> *tmpPtr=new Node<ElemType>(e);
rear->next=tmpPtr;
rear=tmpPtr;
count++;
return true; }
template<typename ElemType>
//队头出队
bool LinkQueue<ElemType>::Outqueue(ElemType &e)
{
if(!Empty())
{
Node<ElemType> *tmpPtr=front->next;
e=tmpPtr->data;
front->next=tmpPtr->next;
if(rear==tmpPtr)
rear=front;
delete tmpPtr;
count--;
return true;
}
else
return false;
}
template<typename ElemType>
//返回队头元素
bool LinkQueue<ElemType>::GetHead(ElemType &e) const
{
if(!Empty())
{
e=front->next->data;
return true;
}
else
return false; }
template<typename ElemType>
//visit
void LinkQueue<ElemType>::Traverse(void(*visit)(const ElemType &))const
{
for(Node<ElemType> *tmpPtr=front->next;tmpPtr;tmpPtr=tmpPtr->next)
(*visit)(tmpPtr->data);
}
template<typename ElemType>
//复制构造
LinkQueue<ElemType>::LinkQueue(const LinkQueue<ElemType> &copy)
{
rear=front=new Node<ElemType>;
count=;
for(Node<ElemType> *tmpPtr=copy.front->next;tmpPtr!=NULL;tmpPtr=tmpPtr->next)
Inqueue(tmpPtr->data);
}
template<typename ElemType>
//重载=operator
LinkQueue<ElemType> &LinkQueue<ElemType>::operator=(const LinkQueue<ElemType> &copy)
{
if(&copy!=this)
{
Clear();
for(Node<ElemType> *tmpPtr=copy.front->next;tmpPtr!=NULL;tmpPtr=tmpPtr->next)
Inqueue(tmpPtr->data);
return *this;
} }

LinkQueue(链队列)的更多相关文章

  1. C语言实现链队列的初始化&进队&出队

    /*链表实现队列的一系列操作*/ #include<stdio.h> #include<stdlib.h> #define OK 1 #define ERROR 0 typed ...

  2. 【Java】 大话数据结构(7) 循环队列和链队列

    本文根据<大话数据结构>一书,实现了Java版的循环队列.链队列. 队列:只允许在一端进行插入操作,而在另一端进行删除操作的线性表. 1.循环队列 队列的顺序储存结构:用数组存储队列,引入 ...

  3. 队列的理解和实现(二) ----- 链队列(java实现)

    什么是链队列 链队是指采用链式存储结构实现的队列,通常链队用单链表俩表示.一个链队显然需要两个分别指示队头和队尾的指针,也称为头指针和尾指针,有了这两个指针才能唯一的确定. package 链队列; ...

  4. C语言链队列

    链队列类似于单链表,为了限制只能从两端操作数据,其结构体内有2个指针分别指向头尾,但队列里的节点用另一种结构体来表示,头尾指针则为指向该结构体的类型.只能通过操作头尾指针来操作队列. typedef ...

  5. java实现链队列

    java实现链队列的类代码: package linkqueue; public class LinkQueue { class Element { Object elem; Element next ...

  6. 数据结构 - 链队列的实行(C语言)

    数据结构-链队列的实现 1 链队列的定义 队列的链式存储结构,其实就是线性表的单链表,只不过它只能尾进头出而已, 我们把它简称为链队列.为了操作上的方便,我们将队头指针指向链队列的头结点,而队尾指针指 ...

  7. 用OC基于链表实现链队列

    一.简言 在前面已经用C++介绍过链队列的基本算法,可以去回顾一下https://www.cnblogs.com/XYQ-208910/p/11692065.html.少说多做,还是上手撸代码实践一下 ...

  8. javascript实现数据结构与算法系列:队列 -- 链队列和循环队列实现及示例

    1 队列的基本概念 队列(Queue):也是运算受限的线性表.是一种先进先出(First In First Out ,简称FIFO)的线性表.只允许在表的一端进行插入,而在另一端进行删除. 队首(fr ...

  9. java与数据结构(8)---java实现链队列

    链队列 实际上就是单链表,只是规定了删除在队头进行,添加在队尾进行. 链队列代码结构 package list.queue; public interface Queuable<T>; p ...

  10. 链队列之C++实现

    链队列时建立在单链表的基础之上的.由于是动态分配节点内存,所以无需判满. 链队列的形式如下: 1.队列空 2.队列存在数据 下面介绍下C++实现的链队列,VC6下调试通过. 1.文件组织 2.lq.h ...

随机推荐

  1. php倒计时防刷新

    <?php //php的时间是以秒算.js的时间以毫秒算 date_default_timezone_set("Asia/Hong_Kong");//地区 //配置每天的活动 ...

  2. 跨域,json与jsonp格式

    好久都没有写随笔了,最近大家都忙着考试要放假了,我也要忙一忙喽.....不过再忙我还是来啦 简单的说,json是一种轻量级的数据交换格式.平时我们使用ajax等使用的一种数据形式,那么今天就说说jso ...

  3. 【转】JS容器拖拽效果,并通过cookie保存拖拽各容器的所在位置

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. KBEngine WebConsole Guide

    https://github.com/kbengine/kbengine/tree/master/docs

  5. Java IO学习笔记(四)打印流

    1.只有输出流才有打印流:PrintWriter和PrintStream分别针对字符和字节,提供了重载的print,Println方法用于多种数据类型的输出.PrintWriter和PrintStre ...

  6. VB6之写注册表

    难免会遇到写注册表的情况,写了个实用点的RegWrite函数.为了减少代码量,用WScript.Shell取代了API来实现. 使用方式就在注释中了,就不再过多解释了.PS:注释比实现代码要丰富多了, ...

  7. vijos1059题解

    题目: XC的儿子小XC最喜欢玩的游戏用积木垒漂亮的城堡.城堡是用一些立方体的积木垒成的,城堡的每一层是一块积木.小XC是一个比他爸爸XC还聪明的孩子,他发现垒城堡的时候,如果下面的积木比上面的积木大 ...

  8. 如何将App程序发布到苹果App Store

    原文网上抄录 发布步骤登陆苹果开发者中心http://developer.apple.com(99美元账号)进入itunes connect选择Manage Your Apps选择Add New Ap ...

  9. RabbitMQ系列教程之六:远程过程调用(RPC)

    远程过程调用(Remote Proceddure call[RPC])(本实例都是使用的Net的客户端,使用C#编写)  在第二个教程中,我们学习了如何使用工作队列在多个工作实例之间分配耗时的任务.  ...

  10. 为Dynamics 365写一个简单程序实现解决方案一键迁移

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复258或者20170627可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...