进击的数据结构之六队列的基本操作-顺序结构
2013-10-31 20:54
513 查看
#include "stdio.h" #include "stdlib.h" #include "io.h" #include "math.h" #include "time.h" #define OK 1 #define ERROR 0 #define TRUE 1 #define FALSE 0 #define MAXSIZE 20 /* 存储空间初始分配量 */ typedef int Status; typedef int QElemType; /* QElemType类型根据实际情况而定,这里假设为int */ /* 循环队列的顺序存储结构 */ typedef struct { QElemType date[MAXSIZE]; int front; /* 头指针 */ int rear; /* 尾指针,若队列不空,指向队列尾元素的下一个位置 */ }SqQueue; Status InitQueue(SqQueue *Q) { Q->front=0; Q->rear=0; return 1; } Status ClearQueue(SqQueue *Q) { Q->front=0; Q->rear=0; return 1; } Status QueneEmpty(SqQueue Q) { if(Q.front==Q.rear) return 1; return 0; } Status GetHead(SqQueue Q,QElemType &e) { if(QueneEmpty(Q)) return 0; e=Q.date[Q.front]; return 1; } Status EnQueue(SqQueue *Q,QElemType e) { if((Q->rear+1)%MAXSIZE==Q->front) return 0; Q->date[Q->rear]=e; Q->rear=(Q->rear+1)%MAXSIZE; return 1; } Status DeQueue(SqQueue *Q,QElemType &e) { if( QueneEmpty(*Q)) return 0; e=Q->date[Q->front]; Q->front=(Q->front+1)%MAXSIZE; return 1; } int QueueLength(SqQueue Q) { return ((Q.rear-Q.front+MAXSIZE)%MAXSIZE); } Status QueueTraverse(SqQueue Q) { int i,e; if (QueneEmpty(Q)) return 0; while(!QueneEmpty(Q)) { GetHead(Q,e); printf("%d\n",e); Q.front=(Q.front+1)%MAXSIZE; } }
相关文章推荐
- 队列的基本操作(顺序结构)C/C++
- 数据结构--顺序队列基本操作
- 【数据结构与算法】基本数据结构——队列的顺序表示
- 数据结构-循环顺序队列的基本操作
- hrbustoj 1545:基础数据结构——顺序表(2)(数据结构,顺序表的实现及基本操作,入门题)
- 数据结构-队列顺序结构的实现和操作
- 循环队列的相关操作(顺序结构)
- 顺序队列(非循环)的基本操作
- 数据结构——队列的基本操作
- 数据结构循环队列的基本操作(C语言)
- 数据结构之线性结构---队列 顺序储存
- 顺序队列基本操作
- 数据结构-循环队列的基本实现操作
- 用顺序结构表示栈的各种基本操作
- 数据结构之队列的基本操作入队出队初始化删除-c++代码实现及运行实例结果
- 3335 数据结构实验之栈与队列八:栈的基本操作
- 面向数据c++数据结构之基本数据结构(队列)--【美】Jan Harrington 陈博译
- 顺序队列基本操作
- 数据结构中线性顺序表的基本操作(增删改查及合并)
- 【数据结构】顺序栈的基本操作操作---C/C++