ADT
来源:互联网 发布:统计局数据由哪几部分 编辑:程序博客网 时间:2024/05/21 19:25
//ADT Squencial Queue#define OK 1#define ERROR 0#define TRUE 1#define FALSE 0#define OVERFLOW -1#define MAXQSIZE 100#define INCREASEQSIZE 10typedef int QElemType;typedef int Status;typedef struct { QElemType *base; int front;//头指针 int reer;//尾指针 int length;//队列长度}SqQueue;//构造一个空队列Status InitQueue(SqQueue &Q) { Q.base = (QElemType *)malloc(MAXQSIZE * sizeof(QElemType)); if(!Q.base) exit(OVERFLOW); Q.front = Q.reer = 0; Q.length = MAXQSIZE; return OK;}//销毁队列QStatus DestroyQueue(SqQueue &Q) { free(Q.base); Q.front = Q.reer = 0; Q.length = 0; return OK;}//清空队列Status ClearQueue(SqQueue &Q) { Q.front = Q.reer = 0; Q.length = 0; return OK;}//插入元素Status EnQueue(SqQueue&Q, QElemType e) { if((Q.reer+1)%Q.length == Q.front) { Q.base = (QElemType *)realloc(Q.base, sizeof(QElemType) * (Q.length + INCREASEQSIZE)); Q.length += INCREASEQSIZE; } Q.base[Q.reer] = e; Q.reer = (Q.reer + 1) % Q.length; return OK;}//删除元素Status DeQueue(SqQueue &Q,QElemType &e) { if(Q.front == Q.reer) return ERROR; e = Q.base[Q.front]; Q.front = (Q.front + 1) % Q.length; return OK;}//判断队列是否为空Status QueueEmpty(SqQueue Q) { if(Q.front == Q.reer) return TRUE; return FALSE;}//求队列长度int QueueLength(SqQueue Q) { return (Q.reer - Q.front + Q.length) % Q.length;}//求队头元素的值Status GetHead(SqQueue Q, QElemType &e) { if(Q.front == Q.reer) return ERROR; e = Q.base[Q.front]; return OK;}//遍历Status QueueTraverse(SqQueue Q) { for(int i = Q.front; i != Q.reer; i = (i + 1) % Q.length) { if(i == Q.front) cout << Q.base[i]; else cout << ' ' << Q.base[i]; } cout << endl;}
阅读全文
0 0
- ADT
- adt
- ADT
- ADT
- ADT
- ADT
- ADT
- ADT
- ADT
- ADT
- ADT
- ADT
- ADT
- ADT
- 删除ADT,重新安装ADT
- 日志ADT
- ADT(链表)
- ADT 配置
- React-Native开发总结-前端常规需求实现方案
- Android Open Source Project Patches
- 我的第三篇
- 【BZOJ2144】Throw 数论
- spark中调用逻辑回归
- ADT
- TensorFlow训练线性回归
- 14.5 HTTPS 与代理
- CDH安装
- 基本语法
- Java连接Sql Server 2008的简单数据库应用
- Scala类型参数——泛型之逆变
- 短路
- 二、IDEA中配置maven