数据结构 第七周 项目一 建立顺序环形队列算法库
来源:互联网 发布:20元左右小礼品 知乎 编辑:程序博客网 时间:2024/06/05 17:07
烟台大学
作者 吴玉然
题目 建立顺序环形队列算法库
时间 2017 11 16
sqqueue.h 代码
typedef char ElemType; #define MaxSize 5 typedef struct { ElemType data[MaxSize]; int front, rear; }SqQueue; void InitQueue(SqQueue *&q); //初始化顺序环形队列 void DestroyQueue(SqQueue *&q); //销毁顺序环形队列 bool QueueEmpty(SqQueue *q); //判断顺序环形队列是否为空 int QueueLength(SqQueue *q); //返回队列中元素个数,也称队列长度 bool enQueue(SqQueue *&q, ElemType e); //进队 bool deQueue(SqQueue *&q, ElemType &e); //出队
main.cpp函数
#include <iostream> #include "sqstack.h" using namespace std; int main() { SqQueue *s; ElemType e; cout << "初始化队列" << endl; InitQueue(s);//初始化顺序环形队列 cout << "a、b、c进队" << endl; enQueue(s, 'a'); enQueue(s, 'b'); enQueue(s, 'c'); cout << "判断队列是否为空:"; if (QueueEmpty(s))//判断顺序环形队列是否为空 cout << "空" << endl; else cout << "非空" << endl; deQueue(s, e);//出队 cout << "队列中元素的个数为:"<<QueueLength(s); enQueue(s, 'd'); enQueue(s, 'e'); enQueue(s, 'f'); cout << endl << "队列中元素的个数为:"<<QueueLength(s); cout << endl << "删除队列" << endl; return 0; }sqqeue.cpp
#include "sqstack.h" #include <iostream> #include <malloc.h> using namespace std; void InitQueue(SqQueue *&q) //初始化顺序环形队列 { q = (SqQueue *)malloc(sizeof(SqQueue)); q->front = q->rear = 0; } void DestroyQueue(SqQueue *&q) //销毁顺序环形队列 { free(q); } bool QueueEmpty(SqQueue *q) //判断顺序环形队列是否为空 { return (q->front == q->rear); } int QueueLength(SqQueue *q) //返回队列中元素个数,也称队列长度 { return (q->rear - q->front + MaxSize) % MaxSize; } bool enQueue(SqQueue *&q, ElemType e) //进队 { if ((q->rear + 1) % MaxSize == q->front) return false; q->rear = (q->rear + 1) % MaxSize; q->data[q->rear] = e; return true; } bool deQueue(SqQueue *&q, ElemType &e) //出队 { if (q->rear == q->front) return false; q->front = (q->front + 1) % MaxSize; e = q->data[q->front]; return true; }
阅读全文
0 0
- 第七周项目一 建立顺序环形队列算法库
- 第七周 项目一 建立顺序环形队列算法库
- 第七周-项目一 建立顺序环形队列算法库
- 第七周项目一--建立顺序环形队列算法库
- 第七周 项目一 建立顺序环形队列算法库
- 第七周项目一建立顺序环形队列算法库
- 第七周 项目一建立顺序环形队列算法库
- 第七周 项目一 建立顺序环形队列算法库
- 第七周项目一 建立顺序环形队列算法库
- 第七周项目一 建立顺序环形队列算法库
- 第七周 项目一 建立顺序环形队列算法库
- 第七周 项目一 建立顺序环形队列算法库
- 数据结构第七周项目一-建立顺序环形队列算法库
- 数据结构 第七周 项目一 建立顺序环形队列算法库
- 数据结构第七周项目(一)——建立顺序环形队列算法库
- 第七周数据结构之自建算法库——顺序环形队列【项目1 - 建立顺序环形队列算法库】
- 第七周--数据结构--建立顺序环形队列算法库
- 第七周项目1-建立顺序环形队列算法库
- 第十一周——操作用邻接表存储的图
- html meta标签的那些事儿
- 优秀开源项目之六:C++日志框架 Google Glog
- sql基本操作2
- 记录一个Spring MVC Controller层,跳转到前端页面以及返回参数的包装类
- 数据结构 第七周 项目一 建立顺序环形队列算法库
- 关于iOS GangSDK的使用,为App快速集成社群公会模块
- 将一台XP添加到WindowsServer2008的域中时不能联系域的域控制器的原因
- 脚本优化
- 数据结构第七周项目(一)——建立顺序环形队列算法库
- phpstorm 输入法中文不同步 phpstorm 输入法不跟随光标解决办法 win7系统新安装的phpstorm2017.2版本,试了很多输入法,要么是不显示候选次,要么是输入法候选词总是在屏幕右
- 使用showdown.js将Markdown文档转换为HTML
- Palisade.Decision.Tools.Suite.Industrial.v5.5 1CD(不确定性定量分析与决策)
- 原型模式