《大话数据结构》第四章 队列
来源:互联网 发布:工程算量软件 编辑:程序博客网 时间:2024/06/01 07:32
队列
ADT 队列
Operation:
InitQueue(*Q);
DestroyQueue(*Q);
ClearQueue(*Q);
QueueEmpty(Q);
GetHead(Q,*e);
EnQueue(*Q,e);
DeQueue(*Q,*e);
QueueLength(Q);
结构代码
typedef int QElemType;typedef struct{ int front; int rear; QElemType data[MaxSize];}SqQueue;
循环队列
初始化
Status InitQueue(SqQueue *Q){ Q->front=0; Q->rear=0; return OK; }
循环队列的长度
int QueueLength(SqQueue Q){ return (rear-front+MaxSize)%MaxSize;}
入队
Status EnQueue(SqQueue *Q, QElemType e){ if((Q->rear+1)%MaxSize==Q->front) return ERROR; Q->data[Q->rear]=e; Q->rear=(Q->rear+1)%MaxSize; return OK;}
出队
Status DeQueue(SqQueue *Q, QElemType *e){ if(Q->rear==Q->front) return ERROR; *e=Q->data[Q->front]; Q->front=(Q->front+1)%MaxSize; return OK;}
队列的链式存储结构
结构代码
链队列有头结点
typedef int QElemType;typedef struct QNode{ QElemType data; struct QNode *next;}QNode, *QueuePtr;typedef struct LinkQueue{ QueuePtr front, rear;}LinkQueue;
入队
Status EnQueue(LinkQueue *Q, QElemType e){ QueuePtr s=(QueuePtr)malloc(sizeof(QNode)); if(!s) //储存分配失败 exit(OVERFLOW); s->data=e; s->next=NULL; Q->rear->next=s; Q->rear=s; return OK;}
出队
Status DeQueue(LinkQueue *Q, QElemType *e){ if(Q->front==Q->rear) return ERROR; QueuePtr p; p=Q->front->next; *e=p->data; Q->front->next=p->next; //若队头是队尾,则删除后将rear指向头结点 if(Q->rear=p) Q->rear=Q->front; free(p); return OK;}
阅读全文
0 0
- 《大话数据结构》第四章 队列
- 《大话数据结构》第四章栈与队列
- 大话数据结构--第四章 栈与队列
- 《大话数据结构》第四章 栈与队列
- 《大话数据结构》笔记之 第四章 栈与队列
- 大话数据结构第四章——栈与队列
- 大话数据结构 code 第四章 05顺序队列_Queue
- 大话数据结构 code第四章 06链队列_Link
- 大话数据结构 第四章 栈与队列 (读书笔记)
- 「笔记」《大话数据结构》第四章:栈与队列
- [数据结构]第四章-队列
- 大话数据结构之队列
- 大话数据结构 code 第四章 01顺序栈_Stack
- 大话数据结构 code 第四章 03链栈_LinkStack
- 大话数据结构第四章栈十个问题及解答
- 大话数据结构 --栈和队列
- C++数据结构路程:第四章,链式队列
- 《大话数据结构》第4章.栈与队列
- 线程安全队列(三)
- Tarjan算法求桥和割点
- Git基础教程
- 进程、线程与协程
- echarts3--tooltip-position
- 《大话数据结构》第四章 队列
- mysql 实现 substring+lastindexof 的方法
- 关于变量交换(异或)
- HDU 5127 Dogs' Candies(瞎暴力)
- 安全线程队列(四)
- Python-Numpy的tile函数
- Oracle 11g服务器监听配置
- Fedora15开启ROOT帐号登录
- 莫比乌斯反演(bzoj 2301: [HAOI2011]Problem b)