#ifndef _CONST_H_
#define _CONST_H_
#include
#include
typedef enum
{
False = 0,
True,
}Bool;
typedef int ElemType;
#define QUEUE_MAX_SIZE 10
#define STACK_INIT_SIZE 10
#define STACK_INCREMENT_SIZE 2
#define Null ((void *)0)
typedef enum
{
NORMAL = 0,
ERROR,
UNDERFLOW,
OVERFLOW,
STATUSCOUNT,
}Status;
#endif
#ifndef _QUEUE_H_
#define _QUEUE_H_
#include "Const.h"
typedef struct queue
{
ElemType *base;
int front;
int rear;
}Queue, *pQueue;
Status InitQueue(Queue *pQ);
Bool IsQueueFull(pQueue pQ);
Bool IsQueueEmpty(pQueue pQ);
Bool EnQueue(pQueue pQ, ElemType elme);
Bool DeQueue(pQueue pQ, ElemType *e);
void DestoryQueue(pQueue pQ);
void ClearQueue(pQueue pQ);
ElemType GetHead(pQueue pQ);
int GetQueueLength(pQueue pQ);
#endif
#include "Queue.h"
Status InitQueue(Queue *pQ)
{
pQ->front = 0;
pQ->rear = 0;
pQ->base = (ElemType *)malloc(QUEUE_MAX_SIZE * sizeof(ElemType));
if (Null == pQ->base)
{
printf("Can not malloc target size memory");
return ERROR;
}
}
Bool IsQueueFull(pQueue pQ)
{
if ((pQ->rear + 1) % QUEUE_MAX_SIZE == pQ->front)
{
return True;
}
else
{
return False;
}
}
Bool IsQueueEmpty(pQueue pQ)
{
if (pQ->rear == pQ->front)
{
return True;
}
else
{
return False;
}
}
Bool EnQueue(pQueue pQ, ElemType elme)
{
if (IsQueueFull(pQ))
{
printf("The Queue Is Full.");
return False;
}
else
{
pQ->base[pQ->rear] = elme;
pQ->rear = (pQ->rear + 1) % QUEUE_MAX_SIZE;
}
}
Bool DeQueue(pQueue pQ, ElemType *e)
{
if (IsQueueEmpty(pQ))
{
printf("The Queue Is Empty.");
return False;
}
else
{
*e = pQ->base[pQ->front];
pQ->front = (pQ->front + 1) % QUEUE_MAX_SIZE;
return True;
}
}
void DestoryQueue(pQueue pQ)
{
if (pQ->base)
{
free(pQ->base);
}
pQ->rear = 0;
pQ->front = 0;
pQ->base = Null;
}
void ClearQueue(pQueue pQ)
{
pQ->rear = 0;
pQ->front = 0;
}
ElemType GetHead(pQueue pQ)
{
if (IsQueueEmpty(pQ))
{
printf("The queue is empty.");
return 0;
}
return pQ->base[pQ->front];
}
int GetQueueLength(pQueue pQ)
{
return pQ->rear - pQ->front;
}
【数据结构】循环队列 C语言实现
"Queue.h" #include "Queue.h" #include #include ...
不定长链表队列C语言实现
#ifndef _CONST_H_#define _CONST_H_ #include #include typedef enum { ...
数据结构算法C语言实现(十二)--- 3.4循环队列&;队列的顺序表示和实现
一.简述 空队列的处理方法:1.另设一个标志位以区别队列是空还是满:2.少用一个元素空间,约定以队列头指针在队尾指针下一位置上作为队列呈满的状态的标志. 二.头文件 //3_4_part1.h /** ...
C语言数据结构-循环队列的实现-初始化、销毁、清空、长度、队列头元素、插入、删除、显示操作
1.数据结构-循环队列的实现-C语言 #define MAXSIZE 100 //循环队列的存储结构 typedef struct { int* base; //基地址 int _front; //头 ...
C语言实现使用动态数组实现循环队列
我在上一篇博客中实现了使用静态数组来模拟队列的操作. 因为数组的大小已经被指定.无法动态的扩展. 所以在这篇博客中,我换成动态数组来实现. 动态数组能 ...
快学Scala 第三课 (定长数组,变长数组, 数组循环, 数组转换, 数组常用操作)
定长数组定义: val ar = new Array[Int](10) val arr = Array("aa", "bb") 定长数组赋值: arr(0) = ...
数据结构(C语言版)---第三章栈和队列 3.4.2 队列的链式表示和实现(循环队列)
这个是循环队列的实现,至于串及数组这两章,等有空再看,下面将学习树. 源码如下: #include #include #define ...
c语言编程之循环队列
利用链表实现的循环队列,完成了队列的入队和出队,对于队空和队满用了一个flag进行标记.入队flag++,出队flag-- #include"stdio.h" typedef in ...
数据结构:循环队列(C语言实现)
生活中有非常多队列的影子,比方打饭排队,买火车票排队问题等,能够说与时间相关的问题,一般都会涉及到队列问题:从生活中,能够抽象出队列的概念,队列就是一个能够实现"先进先出"的存储结 ...
随机推荐
AMap地图加载完成事件
等宽字体延伸到的 ch 长度单位和动画 animation-timing-function
新知识点get! 等宽字体(monospaced font)是指字符宽度相同的电脑字体.与此相对,字符宽度不尽相同的电脑字体称为比例字体(proportional font). 东亚字体基本都是等宽字 ...
Linux之用户管理
1.添加普通用户 [root@server ~]# useradd chenjiafa //添加一个名为chenjiafa的用户[root@server ~]# passwd chenjiafa ...
Corn Fields(POJ 3254状压dp)
题意: n*m网格1能放0不能放 放的格子不能相邻 求一共多少种可放的方案. 分析: dp[i][j]第i行可行状态j的的最大方案数,枚举当前行和前一行的所有状态转移就行了(不放牛也算一种情况) #i ...
Windows多线程同步系列之三-----事件对象
事件是一个内核事件,内核事件是什么呢,我理解也不深入也不好说,暂且理解为一个内核维护的数据类型吧通过内核事件同步主要 的方法是对事件的信号有和无来进行同步. 比如当我们一个线程进入一段临界代码(独占代 ...
[.NET] 《Effective C#》快速笔记(三)- 使用 C# 表达设计
快速笔记(三)- 使用 C# 表达设计 目录 二十一.限制类型的可见性 二十二.通过定义并实现接口替代继承 二十三.理解接口方法和虚方法的区别 二十四.用委托实 ...
Pollard Rho大质数分解学习笔记
目录 问题 流程 代码 生日悖论 end 问题 给定n,要求对n质因数分解 普通的试除法已经不能应用于大整数了,我们需要更快的算法 流程 大概就是找出\(n=c*d\) 如果\(c\)是素数,结束,不 ...
自定义udf添加一列
//创建得分窗口字典 var dict= new mutable.HashMap[Double, Int]() ){ dict.put(result_Score(i),i) } //自定义Udf函数 ...
PHP定时执行计划任务
一.Windows计划任务 在web 服务下新建需要执行的文件 二.新建bat文件,命名为test.bat,内容如下: D:\php\php.exe -q D:\website\test.php 三. ...