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; +}