1 Star 0 Fork 5

卢国祥/C Data Structure

forked from Shapper/C Data Structure 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
de_queue.cpp 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
Shapper 提交于 3年前 . 添加双端队列
//
// Created by Win10 on 2022/10/31.
//
#include "de_queue.h"
void InitQueue(DeQue &Q) {
Q.front = Q.rear = Q.size = 0;
}
bool QueueEmpty(DeQue Q) {
if (Q.size == 0) return true;
return false;
}
bool QueueFull(DeQue Q) {
if (Q.size == MaxSize) return true;
return false;
}
bool EnQueue_Head(DeQue &Q, ElemType x) {
if (QueueFull(Q)) return false;
Q.front = (Q.front - 1 + MaxSize) % MaxSize;
Q.data[Q.front] = x;
Q.size++;
return true;
}
bool EnQueue_Rear(DeQue &Q, ElemType x) {
if (QueueFull(Q)) return false;
Q.data[Q.rear] = x;
Q.rear = (Q.rear + 1) % MaxSize;
Q.size++;
return true;
}
bool DeQueue_Head(DeQue &Q, ElemType &x) {
if (QueueEmpty(Q)) return false;
x = Q.data[Q.front];
Q.front = (Q.front + 1) % MaxSize;
Q.size--;
return true;
}
bool DeQueue_Rear(DeQue &Q, ElemType &x) {
if (QueueEmpty(Q)) return false;
Q.rear = (Q.rear - 1 + MaxSize) % MaxSize;
x = Q.data[Q.rear];
Q.size--;
return true;
}
bool GetHead(DeQue Q, ElemType &x) {
if (QueueEmpty(Q)) {
return false;
}
x = Q.data[Q.front];
return true;
}
int GetSize(DeQue Q) {
return Q.size;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/noob-coder/c-data-structure.git
git@gitee.com:noob-coder/c-data-structure.git
noob-coder
c-data-structure
C Data Structure
master

搜索帮助