From 9929d5d4ebaccf1d49e90cc4a57784af22aa9cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=A1=E5=9D=82=E6=98=B4?= Date: Wed, 23 Oct 2024 22:30:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=BE=AA=E7=8E=AF=E9=93=BE?= =?UTF-8?q?=E8=A1=A8=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homework3/SeqQueue.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/homework3/SeqQueue.cpp b/homework3/SeqQueue.cpp index 4515169..f0f28d8 100644 --- a/homework3/SeqQueue.cpp +++ b/homework3/SeqQueue.cpp @@ -1,6 +1,9 @@ //SeqQueue.cpp #include "SeqQueue.h" +#include + +using namespace std; void initSeqQueue(SeqQueue &q) { q.front = q.rear = 0; @@ -20,3 +23,20 @@ bool isFull(SeqQueue &q) { return false; } +void enQueue(SeqQueue &q, int e) { + if (isFull(q)) { + cout << "此队列已满" << endl; + return; + } + q.rear = (q.rear + 1) % MAX_SIZE; + q.data[q.rear] = e; +} + +int deQueue(SeqQueue &q) { + if (isEmpty(q)) { + cout << "此队列为空" << endl; + return NULL; + } + return q.data[q.front]; + q.front(q.front - 1) % MAX_SIZE; +}