代码拉取完成,页面将自动刷新
//
// Created by Win10 on 2022/10/30.
//
#include<iostream>
#include "c_queue.h"
using namespace std;
void InitQueue(CQueue &Q) {
Q.front = Q.rear = Q.size = 0;
}
bool QueueEmpty(CQueue Q) {
if (Q.size == 0) return true;
return false;
}
bool QueueFull(CQueue Q) {
if (Q.size == MaxSize) return true;
return false;
}
bool EnQueue(CQueue &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(CQueue &Q, ElemType &x) {
if (QueueEmpty(Q)) return false;
x = Q.data[Q.front];
Q.front = (Q.front + 1) % MaxSize;
Q.size--;
return true;
}
bool GetHead(CQueue Q, ElemType &x) {
if (QueueEmpty(Q)) {
return false;
}
x = Q.data[Q.front];
return true;
}
int GetSize(CQueue Q) {
return Q.size;
}
int main() {
{
CQueue Q;
InitQueue(Q);
for (int i = 1; i <= 5; i++) {
bool f = EnQueue(Q, i);
if (!f) cout << i << endl;
}
ElemType x;
DeQueue(Q, x);
cout << x << endl;
DeQueue(Q, x);
cout << x << endl;
EnQueue(Q, 1);
EnQueue(Q, 2);
cout << Q.front << " " << Q.rear << endl;
if (!EnQueue(Q, 6)) {
cout << "队列已满" << endl;
}
GetHead(Q, x);
cout << x << endl << endl;
while (!QueueEmpty(Q)) {
DeQueue(Q, x);
cout << x << endl;
}
}
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。