博客
关于我
链队列——出入队列
阅读量:297 次
发布时间:2019-03-03

本文共 833 字,大约阅读时间需要 2 分钟。

首先就是定义一个结构结构体 ,用来装队列的头和尾

#include
#include
using namespace std;struct node{ int data; node *nex;};struct Queue{ node *head=new node; node *rear=new node;}Q;/*队列的头和尾*/void get_link(int x,Queue *Q){ node *tail=Q->rear;/*队列尾部*/ while(x--) { node *q=new node; scanf("%d",&q->data); tail->nex=q; q->nex=NULL; tail=q; //Q->rear=q; /*或者这样记录尾部*/ } Q->rear=tail;/*更新尾部*/}void out_link(node *head){ node *q=head->nex; while(q)/*队列不为空*/ { printf("%d\n",q->data); q=q->nex; } head->nex=q; Q.head=head;}int main(){ int x; scanf("%d",&x); node *q = new node; /*表头*/ Q.head=Q.rear=q;/*表头没有数据,尾部有*/ get_link(x,&Q);/*传进去头和尾*/ out_link(Q.head); if(!Q.head->nex)/*判断是否空*/ printf("1\n"); return 0;}

 

转载地址:http://oqsl.baihongyu.com/

你可能感兴趣的文章
Member var and Static var.
查看>>
memcached高速缓存学习笔记001---memcached介绍和安装以及基本使用
查看>>
memcached高速缓存学习笔记003---利用JAVA程序操作memcached crud操作
查看>>
Memcached:Node.js 高性能缓存解决方案
查看>>
memcache、redis原理对比
查看>>
memset初始化高维数组为-1/0
查看>>
Metasploit CGI网关接口渗透测试实战
查看>>
Metasploit Web服务器渗透测试实战
查看>>
Moment.js常见用法总结
查看>>
MongoDB出现Error parsing command line: unrecognised option ‘--fork‘ 的解决方法
查看>>
mxGraph改变图形大小重置overlay位置
查看>>
MongoDB学习笔记(8)--索引及优化索引
查看>>
MQTT工作笔记0009---订阅主题和订阅确认
查看>>
ms sql server 2008 sp2更新异常
查看>>
MS UC 2013-0-Prepare Tool
查看>>
msbuild发布web应用程序
查看>>
MSB与LSB
查看>>
MSCRM调用外部JS文件
查看>>
MSCRM调用外部JS文件
查看>>
MSEdgeDriver (Chromium) 不适用于版本 >= 79.0.313 (Canary)
查看>>