资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
#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)node *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-front=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);
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号