From c9aed649b521c819ecdbe337199b09e2b5d4dab5 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 21:51:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=BE=AA=E7=8E=AF=E9=93=BE?= =?UTF-8?q?=E8=A1=A8=E5=A4=B4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homework3/CMakeLists.txt | 4 +++- homework3/SeqQueue.cpp | 22 ++++++++++++++++++++++ homework3/SeqQueue.h | 23 +++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 homework3/SeqQueue.cpp create mode 100644 homework3/SeqQueue.h diff --git a/homework3/CMakeLists.txt b/homework3/CMakeLists.txt index eae6355..edaf6ba 100644 --- a/homework3/CMakeLists.txt +++ b/homework3/CMakeLists.txt @@ -7,4 +7,6 @@ add_executable(test1 Stack.h Stack.cpp test1.cpp) -add_executable(test2 test2.cpp) +add_executable(test2 test2.cpp + SeqQueue.cpp + SeqQueue.h) diff --git a/homework3/SeqQueue.cpp b/homework3/SeqQueue.cpp new file mode 100644 index 0000000..4515169 --- /dev/null +++ b/homework3/SeqQueue.cpp @@ -0,0 +1,22 @@ +//SeqQueue.cpp + +#include "SeqQueue.h" + +void initSeqQueue(SeqQueue &q) { + q.front = q.rear = 0; +} + +bool isEmpty(SeqQueue &q) { + if (q.front == q.rear) { + return true; + } + return false; +} + +bool isFull(SeqQueue &q) { + if ((q.rear + 1) % MAX_SIZE == q.front) { + return true; + } + return false; +} + diff --git a/homework3/SeqQueue.h b/homework3/SeqQueue.h new file mode 100644 index 0000000..1f66ad9 --- /dev/null +++ b/homework3/SeqQueue.h @@ -0,0 +1,23 @@ +//SeqQueue.h + +#ifndef SEQQUEUE_H +#define SEQQUEUE_H + +#define MAX_SIZE 100 + +typedef struct SeqQueue { + int data[MAX_SIZE]; + int front, rear; +} SeqQueue; + +void initSeqQueue(SeqQueue &q); + +bool isEmpty(SeqQueue &q); + +bool isFull(SeqQueue &q); + +void enQueue(SeqQueue &q, int e); + +int deQueue(SeqQueue &q); + +#endif //SEQQUEUE_H