数据结构C语言版-队列
- #include <stdlib.h>
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- typedef int QElemType;
- typedef struct QNode {
- QElemType data;
- struct QNode *next;
- } QNode, *QueuePtr;
- typedef struct {
- QueuePtr front;
- QueuePtr rear;
- } LinkQueue;
- bool InitQueue(LinkQueue &Q);
- bool DestoryQueue(LinkQueue &Q);
- bool ClearQueue(LinkQueue &Q);
- bool QueueEmpty(LinkQueue Q);
- int QueueLength(LinkQueue Q);
- int GetHead(LinkQueue Q);
- bool EnQueue(LinkQueue &Q, QElemType e);
- bool DeQueue(LinkQueue &Q, QElemType &e);
- void QueueTraverse(LinkQueue Q);
- //Q.front里面是没有数据的
- //Q.rear里面是有数据的
- int main() {
- LinkQueue s;
- InitQueue(s);
- EnQueue(s, 5);
- EnQueue(s, 6);
- EnQueue(s, 7);
- ClearQueue(s);
- EnQueue(s, 8);
- EnQueue(s, 100);
- cout << QueueLength(s) << endl;
- int a;
- DeQueue(s, a);
- cout << a << endl;
- if (QueueEmpty(s)) {
- cout << 'a' << endl;
- }
- cout << GetHead(s) << endl;
- }
- void QueueTraverse(LinkQueue Q) {
- if (Q.front == Q.rear) {
- return;
- }
- QueuePtr tmp = Q.front->next;
- while (tmp != Q.rear) {
- printf("%d ", tmp->data);
- tmp = tmp->next;
- }
- printf("%d\n", tmp->data);
- }
- int GetHead(LinkQueue Q) {
- return Q.front->next->data;
- }
- bool QueueEmpty(LinkQueue Q) {
- if (Q.front == Q.rear) {
- return true;
- }
- return false;
- }
- int QueueLength(LinkQueue Q) {
- int length = 0;
- LinkQueue tmp = Q;
- while (tmp.front) {
- length++;
- tmp.front = tmp.front->next;
- }
- return length - 1;
- }
- bool InitQueue(LinkQueue &Q) {
- Q.front = Q.rear = (QNode *) malloc(sizeof(QNode));
- if (!Q.front) {
- exit(EOVERFLOW);
- }
- Q.front->next = NULL;
- return true;
- }
- bool ClearQueue(LinkQueue &Q) {
- QueuePtr tmp = Q.front->next;
- while (tmp) {
- QueuePtr tp = tmp;
- tmp = tmp->next;
- free(tp);
- }
- Q.rear = Q.front;
- Q.front->next = NULL;
- }
- bool DestoryQueue(LinkQueue &Q) {
- while (Q.front) {
- Q.rear = Q.front->next;
- free(Q.front);
- Q.front = Q.rear;
- }
- return true;
- }
- bool EnQueue(LinkQueue &Q, QElemType e) {
- QueuePtr p = (QueuePtr) malloc(sizeof(QNode));
- if (!p) {
- exit(EOVERFLOW);
- }
- p->data = e;
- p->next = NULL;
- Q.rear->next = p;
- Q.rear = p;
- return true;
- }
- bool DeQueue(LinkQueue &Q, QElemType &e) {
- if (Q.front == Q.rear) {
- return false;
- }
- QueuePtr p = Q.front->next;
- e = p->data;
- Q.front->next = p->next;
- if (Q.rear == p) {
- Q.rear = Q.front;
- }
- free(p);
- return true;
- }
数据结构C语言版-队列的更多相关文章
- 数据结构C语言版 有向图的十字链表存储表示和实现
/*1wangxiaobo@163.com 数据结构C语言版 有向图的十字链表存储表示和实现 P165 编译环境:Dev-C++ 4.9.9.2 */ #include <stdio.h> ...
- c++学习书籍推荐《清华大学计算机系列教材:数据结构(C++语言版)(第3版)》下载
百度云及其他网盘下载地址:点我 编辑推荐 <清华大学计算机系列教材:数据结构(C++语言版)(第3版)>习题解析涵盖验证型.拓展型.反思型.实践型和研究型习题,总计290余道大题.525道 ...
- 数据结构C语言版 表插入排序 静态表
数据结构C语言版 表插入排序.txt两个人吵架,先说对不起的人,并不是认输了,并不是原谅了.他只是比对方更珍惜这份感情./* 数据结构C语言版 表插入排序 算法10.3 P267-P270 编译 ...
- 数据结构C语言版 弗洛伊德算法实现
/* 数据结构C语言版 弗洛伊德算法 P191 编译环境:Dev-C++ 4.9.9.2 */ #include <stdio.h>#include <limits.h> # ...
- 《数据结构-C语言版》(严蔚敏,吴伟民版)课本源码+习题集解析使用说明
<数据结构-C语言版>(严蔚敏,吴伟民版)课本源码+习题集解析使用说明 先附上文档归类目录: 课本源码合辑 链接☛☛☛ <数据结构>课本源码合辑 习题集全解析 链接☛☛☛ ...
- 【数据结构(C语言版)系列三】 队列
队列的定义 队列是一种先进先出的线性表,它只允许在表的一端进行插入,而在另一端删除元素.这和我们日常生活中的排队是一致的,最早进入队列的元素最早离开.在队列中,允许插入的一端叫做队尾(rear),允许 ...
- 深入浅出数据结构C语言版(7)——特殊的表:队列与栈
从深入浅出数据结构(4)到(6),我们分别讨论了什么是表.什么是链表.为什么用链表以及如何用数组模拟链表(游标数组),而现在,我们要进入到对线性表(特意加了"线性"二字是因为存在多 ...
- 【数据结构(C语言版)系列二】 栈
栈和队列是两种重要的线性结构.从数据结构角度看,栈和队列也是线性表,但它们是操作受限的线性表,因此,可称为限定性的数据结构.但从数据类型角度看,它们是和线性表大不相同的两类重要的抽象数据类型. 栈的定 ...
- 深入浅出数据结构C语言版(5)——链表的操作
上一次我们从什么是表一直讲到了链表该怎么实现的想法上:http://www.cnblogs.com/mm93/p/6574912.html 而这一次我们就要实现所说的承诺,即实现链表应有的操作(至于游 ...
随机推荐
- 1503.02531-Distilling the Knowledge in a Neural Network.md
原来交叉熵还有一个tempature,这个tempature有如下的定义: \[ q_i=\frac{e^{z_i/T}}{\sum_j{e^{z_j/T}}} \] 其中T就是tempature,一 ...
- 《转》完美解决微信video视频隐藏控件和内联播放问题
地址:https://blog.csdn.net/xiao190128/article/details/81025378 var u = navigator.userAgent; var isAndr ...
- excle 内部 超链接(锚点)
超连接对象: 1.文档 2.本文档中的位置. 3. 本文重点 指定 链接到 xx表中的xx位置. 第三种连接 类似于 web文档的中 锚点 超连接 看下图 选 择本文档中的位置, 选择 工作表. ...
- Ubuntu16.04 藍牙連上,但是聲音裏面找不到設備
解決辦法: 1. sudo apt-get install blueman bluez* 2. sudo vim /etc/pulse/default.pa 注釋掉下面的代碼: #.ifexists ...
- 机器学习--Lasso回归和岭回归
之前我们介绍了多元线性回归的原理, 又通过一个案例对多元线性回归模型进一步了解, 其中谈到自变量之间存在高度相关, 容易产生多重共线性问题, 对于多重共线性问题的解决方法有: 删除自变量, 改变数据形 ...
- hive上传数据到oracle
# Oracle 建立hive外部表 使用oracle的大数据连接器向建立hive的外部表,在通过在oracle中根据外部表建立内部表(create table as select * from ex ...
- MR汇聚工具步骤
---------------------------------MR汇聚工具步骤------------------------------------- 1.需要连上141服务器 用户:root ...
- hive上传下载数据
------------------------------------------read me--方式1:适用于工具传输--方式2:适用于手动临时性传输---------------------- ...
- 分布式事务Hmily TCC源码--学习整合
一.什么是分布式事务 分布式事务是指事务的参与者.支持事务的服务器.资源服务器以及事务管理器分别位于不同的分布式系统的不同节点上, 本质上来说,分布式事务是为了保证不同数据库的数据一致性 TCC事务主 ...
- Workerman创建聊天室实例
// 标记是全局启动 define('GLOBAL_START', 1); require_once __DIR__ . '/Workerman/Connection.php'; require_on ...