队列的链式存储及其基本运算
来源:互联网 发布:coc所有兵种升级数据 编辑:程序博客网 时间:2024/04/30 06:03
#include <stdio.h>#include <stdlib.h>#define QueueSize 10typedef struct Qnode //链队列的定义{ char data; struct Qnode *next;}Qtype; //链队中节点类型typedef struct qptr{ Qtype *front,*rear; //链队类型}LinkQueue;void InitQueue(LinkQueue *&lq) //初始化队列:置节点*lq的rear和front均为空{ lq=(LinkQueue *)malloc(sizeof(LinkQueue)); lq->rear=lq->front=NULL;}void EnQueue(LinkQueue *&lq,char x) //进队:创建一个新节点,将其链接到链队末尾,并由rear指向它{ Qtype *s; s=(Qtype*)malloc(sizeof(Qtype)); //创建新节点,插入到链队的末尾 s->data=x;s->next=NULL; if(lq->front==NULL&&lq->rear==NULL) lq->rear=lq->front=s; else { lq->rear->next=s; lq->rear=s; }}int DeQueue(LinkQueue *&lq,char x) //出队:将*front节点的data域值赋给x,并删除该节点{ Qtype *p; if(lq->front==NULL&&lq->rear==NULL) return 0; p=lq->front; x=p->data; if(lq->rear==lq->front) //若原队列中只有一个节点,删除后列队变空 lq->rear=lq->front=NULL; else lq->front=lq->front->next; free(p); return 1;}int GetHead(LinkQueue *lq,char &x) //取队头元素:将front节点的data域值赋给x{ if(lq->front==NULL&&lq->rear==NULL) return 0; x=lq->front->data; return 1;}int QueueEmpty(LinkQueue *lq) //判断队空:若链队为空,则返回1,否则返回0{ if(lq->front==NULL&&lq->rear==NULL) return 1; else return 0;}int main(){ LinkQueue *lq; char e; InitQueue(lq); printf("队%s\n",QueueEmpty(lq)==1?"空":"不空"); printf("a进队\n");EnQueue(lq,'a'); printf("b进队\n");EnQueue(lq,'b'); printf("c进队\n");EnQueue(lq,'c'); printf("d进队\n");EnQueue(lq,'d'); printf("队%s\n",QueueEmpty(lq)==1?"空":"不空"); GetHead(lq,e); printf("队头元素:%c\n",e); printf("出队次序:"); while(!QueueEmpty(lq)) { DeQueue(lq,e); printf("%c ",e); } printf("\n");}
有Bug,不知咋改啊
- 队列的链式存储及其基本运算
- 栈的链式存储及其基本运算
- 队列——链式存储结构及其基本运算(链队列的另一种表达方式)
- 队列——链式存储结构及其基本运算
- 第7周实践项目2 队列的链式存储结构及其基本运算的实现
- 栈的链式存储结构及其基本运算的实现
- 栈的链式存储结构及其基本运算的实现
- 栈的链式存储结构及其基本运算的实现
- 栈的链式存储结构及其基本运算实现
- 栈的链式存储结构及其基本运算实现
- 队列的顺序存储结构及其基本运算的实现
- 队列的顺序存储结构及其基本运算的实现
- 栈的链式存储结构及其运算
- 栈——链式存储结构及其基本运算
- 字符串链式存储结构的基本运算
- 第六周:栈的链式存储结构及其基本运算实现
- 队列——顺序存储结构及其基本运算(循环队列的另一种表达方式)
- 数据结构-链式存储-基本运算
- poj 1364(差分约束-bellmanford)
- 系统的版本号这么来获取
- JAVA实现本月国际国内节日
- POJ 2151 Check the difficulty of problems
- Ubuntu Server(64位) 安装Openoffice4,SWFTools 完成在线文档预览
- 队列的链式存储及其基本运算
- linux中IO调度算法小结
- jquery.validate 自定义验证方法
- .NET面试题再续
- Android动画学习笔记-Android Animation
- 深入学习Make命令和Makefile(下)
- AsyncTask
- GSL区域间隔收敛性判定
- ORACLE中的to_char函数