链队
来源:互联网 发布:网络语66是什么意思 编辑:程序博客网 时间:2024/06/05 08:29
#include<stdio.h>#include<stdlib.h>#include<malloc.h>typedef int type;typedef struct Node{ type info; struct Node*next;}node;//队列声明,保存头指针,尾指针typedef struct{ node *front; node *rear;}queue;//初始化一个空队列并返回其指针queue* init(){ queue *head=(queue*)malloc(sizeof(queue)); head->front=head->rear=NULL;}//打印一个队列void display(queue*head){ node *p=head->front; while(p){ printf("%5d",p->info); p=p->next; } printf("\n");}//入队void insert(queue*head){ node*pre; pre=(node*)malloc(sizeof(node)); pre->next=NULL; scanf("%d",&pre->info); if(!head->front)//如果是空队列,则front和rear指针指向该节点 head->front=head->rear=pre; else{//否则,在尾部插入 head->rear->next=pre; head->rear=pre; }}//销毁一个队列void destory(queue*head){ node*pre=head->front,*p; while(pre) { p=pre->next; free(pre); pre=p; } free(head);}//出队void dele(queue *head){ node*p; if(!head->front) printf("NULL\n"); else{//非空队列 p=head->front; head->front=p->next; free(p); if(!head->front)//如果是删除了最后一个节点,队列置空 head->rear=NULL; }}//建立一个长度为n的队列void create(queue *head,int n){ int i; for(i=1;i<=n;i++) insert(head);}
0 0
- 链队
- 链队
- 链队
- 链队
- 链队
- 链队
- 链队
- 链队
- 链队
- 链队
- 数据结构-链队
- 数据结构--链队
- 链队 尹成
- 数据结构(三)-链队
- 舞伴问题(链队)
- 第七周 周一 链队
- 各种数据结构完整实现之 链队
- 算法与数据结构之八----链队
- USACO3.2.4 Feed Ratios (ratios)
- python 字典有序
- query table row counts for versioned table in Netezza
- 分布式版本控制-Git(一)
- orge工具
- 链队
- IOS7开发~Images.xcassets
- 出租车led广告的媒体传播价值分析
- 学术休假-区号查询
- (hdu step 2.1.2)How many prime numbers(判断一个数是否是质数)
- MongoDB笔记5:MongoDB 不能正常启动的修复
- USACO3.2.5 Magic Squares (msquare)
- 双向链表
- Silverlight -dataGrid 常用属性