diff --git a/homework3/SeqQueue.cpp b/homework3/SeqQueue.cpp index f0f28d8..01f583c 100644 --- a/homework3/SeqQueue.cpp +++ b/homework3/SeqQueue.cpp @@ -28,8 +28,8 @@ void enQueue(SeqQueue &q, int e) { cout << "此队列已满" << endl; return; } - q.rear = (q.rear + 1) % MAX_SIZE; q.data[q.rear] = e; + q.rear = (q.rear + 1) % MAX_SIZE; } int deQueue(SeqQueue &q) { @@ -37,6 +37,7 @@ int deQueue(SeqQueue &q) { cout << "此队列为空" << endl; return NULL; } - return q.data[q.front]; - q.front(q.front - 1) % MAX_SIZE; + int returnE = q.data[q.front]; + q.front = (q.front + 1) % MAX_SIZE; + return returnE; } diff --git a/homework3/test2.cpp b/homework3/test2.cpp index 98f114b..dd10ac4 100644 --- a/homework3/test2.cpp +++ b/homework3/test2.cpp @@ -1,8 +1,25 @@ //test2.cpp #include +#include"SeqQueue.h" //SeqQueue类见第三问 using namespace std; int main() { + SeqQueue q; + initSeqQueue(q); + for (int i = 1; i <= 8; ++i) { + enQueue(q, i); + } + int present = 1; + while (!isEmpty(q)) { + if (present == 1) { + cout << deQueue(q) << " "; + present = 2; + } else { + enQueue(q, deQueue(q)); + present = 1; + } + } + cout << endl; return 0; }