1 / 4
文档名称:

数据结构——链队列.doc

格式:doc   页数:4页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

数据结构——链队列.doc

上传人:drp539603 2015/8/30 文件大小:0 KB

下载得到文件列表

数据结构——链队列.doc

相关文档

文档介绍

文档介绍:#include<iostream>
using namespace std;
typedef struct QNode //元素结点
{
int data;
struct QNode *next;
}QNode, *QueuePtr;
typedef struct //特殊结点
{
QueuePtr front; //队头指针
QueuePtr rear; //队尾指针
}LinkQueue;
void InitQueue (LinkQueue &Q)//初始化
{
==(QueuePtr)malloc(sizeof(QNode));
if (!) cout<<"初始化失败!!!"<<endl;
else
{
->next=NULL;
cout<<"链队列初始化成功!!!"<<endl;
}
}
void DestroyQueue (LinkQueue &Q)//销毁
{
while()
{
=->next;
free();
=;
}
if(!) cout<<"链队列已销毁!!!"<<endl;
}
void EnQueue (LinkQueue &Q,int e)//入队
{
QueuePtr p;
p=(QueuePtr)malloc(sizeof(QNode));
if (!p) cout<<"操作失败!!!"<<endl;
else
{
p->data = e;
p->next = NULL;
->next=p;
=p;
}
}
void PrintQueue(LinkQueue Q)
{
QueuePtr p;
p=->next;
while(p)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
void DeQueue (LinkQueue &Q, int &e)
{
QueuePtr p;
if (==) cout<<"操作失败!!!"<<endl;
else
{
p=->next;
e=p->data;
->next=p->next;
if (==p) =;
free(p);
cout<<"删除后链队列为: ";
PrintQueue(Q);
}
}
int QueueEmpty(LinkQueue Q)
{
if (==) {cout<<"链队列为空!!!"<<endl;return 0;}
else {cout<<"链队列不为空!!!"<<endl;return 1;}
}
void ClearQueue(LinkQueue &Q)
{
QueuePtr p;
while(!=)