链式队列Microsoft Word 文档.doc

上传人:pu****.1 文档编号:557951938 上传时间:2023-09-02 格式:DOC 页数:3 大小:90.50KB
返回 下载 相关 举报
链式队列Microsoft Word 文档.doc_第1页
第1页 / 共3页
链式队列Microsoft Word 文档.doc_第2页
第2页 / 共3页
链式队列Microsoft Word 文档.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《链式队列Microsoft Word 文档.doc》由会员分享,可在线阅读,更多相关《链式队列Microsoft Word 文档.doc(3页珍藏版)》请在金锄头文库上搜索。

1、#include#includetypedef int datatype;typedef struct link_nodedatatype info;struct link_node *next;node;typedef structnode *front,*rear;queue;queue *init()queue *qu;qu=(queue*)malloc(sizeof(queue);qu-front=NULL;qu-rear=NULL;return qu;int empty(queue *qu)return (qu-front?0:1);void display(queue *qu)no

2、de *p;printf(n);p=qu-front;if(!p) printf(n单链表是空的!);elseprintf(n单链表各个结点的值为:n);while(p)printf(%5d,p-info);p=p-next;datatype read(queue *qu)if(!qu-front) printf(n链式栈是空的!);exit(1);return(qu-front-info);queue *insert(queue *qu,datatype x)node *p;p=(node*)malloc(sizeof(node);p-info=x;p-next=NULL;if(qu-fro

3、nt=NULL)qu-front=qu-rear=p;elsequ-rear-next=p;qu-rear=p;return qu;queue *dele(queue*qu)node *q;if(!qu-front) printf(队列为空,无法删除!);return qu;q=qu-front;qu-front=q-next;free(q);if(qu-front=NULL) qu-rear=NULL;return qu;void main()queue*qu=init();int i,j,k;printf(你开始建立的链式队列的结点数为:);scanf(%d,&i);for(j=0;ji;j+)scanf(%d,&k);qu=insert(qu,k);display(qu);printf(n);printf(队首结点值为:%dn,read(qu);qu=dele(qu);display(qu);printf(n);scanf(%d,&k);qu=insert(qu,k);display(qu);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号