链队列的基本操作Word格式文档下载.docx

上传人:b****6 文档编号:19689672 上传时间:2023-01-08 格式:DOCX 页数:7 大小:15.31KB
下载 相关 举报
链队列的基本操作Word格式文档下载.docx_第1页
第1页 / 共7页
链队列的基本操作Word格式文档下载.docx_第2页
第2页 / 共7页
链队列的基本操作Word格式文档下载.docx_第3页
第3页 / 共7页
链队列的基本操作Word格式文档下载.docx_第4页
第4页 / 共7页
链队列的基本操作Word格式文档下载.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

链队列的基本操作Word格式文档下载.docx

《链队列的基本操作Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《链队列的基本操作Word格式文档下载.docx(7页珍藏版)》请在冰豆网上搜索。

链队列的基本操作Word格式文档下载.docx

QueuePtrfront;

QueuePtrrear;

}LinkQueue;

voidInitQueue_L(LinkQueue&

Q)

{//初始化队列

Q.front=Q.rear=newLNode;

Q.front->

next=NULL;

}

intIsEmpty(LinkQueue 

*Q)

if(Q->

front==Q->

rear)

{

return(TRUE);

}

else

return(FALSE);

//队列是否为空或为满

voidqueueexist(LinkQueue*Q)

cout<

<

"

该队列为空"

endl;

elseif(Q->

rear->

next!

=NULL)

该队列为满"

该队列既不为空也不为满"

//构造队列,数据元素由键盘输入

voidCreateQueue_L(LinkQueue&

QElemTypetemp;

LNode*p;

输入要插入的队列值(输入-1结束)"

cin>

>

temp;

while(temp!

=-1)

p=newLNode;

p->

data=temp;

Q.rear->

next=p;

Q.rear=p;

//入队操作

intEnterQueue(LinkQueue*Q,QElemTypex)

{//将数据元素x插入到队列Q中

 

LNode*NewNode=newLNode;

if(NewNode!

NewNode->

data=x;

NewNode->

Q->

next=NewNode;

Q->

rear=NewNode;

return(TRUE);

elsereturn(FALSE);

//溢出

//出队操作

intDeleteQueue(LinkQueue*Q,QElemType*x)

{//将队列Q的队头元素出队,并存放到x所指的存储空间中

p=Q->

front->

next;

next=p->

//队头元素p出队

rear==p)//如果队中只有一个元素p,则p出队后成为空队

rear=Q->

front;

*x=p->

data;

free(p);

//释放存储空间

//队列长度

voidQueueLength_L(LinkQueueQ)

intlength=0;

if(IsEmpty(&

Q));

LNode*p=newLNode;

p=Q.front->

while(p)

length++;

p=p->

该链队列的长度为:

length<

//由头到尾依次输出队列的数据元素

voidOutputQueue_L(LinkQueueQ)

if(Q.front==Q.rear)cout<

空对列"

队列的元素依次为:

;

p->

data<

"

//销毁队列

voidDestroyQueue_L(LinkQueue&

while(Q.front)

Q.rear=Q.front->

deleteQ.front;

Q.front=Q.rear;

voidmain()

intflag=1,select;

☆☆☆☆链队的基本操作☆☆☆☆"

☆1.请输入链队列元素:

☆ 

☆2.判断链队列是否为空或为满☆"

☆3.当前队头元素出队并将其输出链队列各元素☆ 

☆4.将x入队并输出链队列各元素☆ 

☆5.当前链队列的长度☆ 

☆6.销毁队列☆ 

☆7.退出☆ 

while(flag)

请选择:

select;

LinkQueueQ;

intx;

switch(select)

case1:

InitQueue_L(Q);

CreateQueue_L(Q);

OutputQueue_L(Q);

break;

case2:

queueexist(&

Q);

case3:

DeleteQueue(&

Q,&

x);

case4:

输入要入队的元素x:

x;

EnterQueue(&

Q,x);

case5:

QueueLength_L(Q);

case6:

DestroyQueue_L(Q);

销毁成功!

可以再重新建立"

case7:

flag=0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1