1 Star 0 Fork 0

xwjdxx/Data-Structure

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SqQueue.cpp 934 Bytes
一键复制 编辑 原始数据 按行查看 历史
2809708153@qq.com 提交于 2023-10-13 01:43 . 代码
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define MaxSize 20
typedef int ElemType;
typedef struct {
ElemType data[MaxSize];
int front, rear; //β
} SqQueue;
//ʼ
void InitList(SqQueue*& sq) {
sq->front = sq->rear = 0;
}
//ٶ
int DestroyQueue(SqQueue*& sq) {
free(sq);
return 1;
}
//
int EnQueue(SqQueue*& sq, ElemType x) {
if ((sq->rear+1)%MaxSize==sq->front)
return 0;
else {
sq->rear = (sq->rear + 1) % MaxSize;
sq->data[sq->rear] = x;
return 1;
}
}
//
int DeQueue(SqQueue*& sq, ElemType& x) {
if (sq->front == sq->rear)
return 0;
else {
sq->front= (sq->front + 1) % MaxSize;
x = sq->data[sq->front];
return 1;
}
}
//ȡͷԪ
int GetHead(SqQueue* sq, ElemType& x) {
if (sq->front == sq->rear)
return 0;
else {
x = sq->data[(sq->front + 1) % MaxSize];
return 1;
}
}
//ж϶ӿ
int QueueEmpty(SqQueue* sq) {
return sq->front == sq->rear;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/xwjdxx/Data-Structure.git
git@gitee.com:xwjdxx/Data-Structure.git
xwjdxx
Data-Structure
Data-Structure
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385