第二题八个数字测试完成

This commit is contained in:
2024-10-24 00:31:27 +08:00
parent 9929d5d4eb
commit 368ee44fad
2 changed files with 21 additions and 3 deletions
+4 -3
View File
@@ -28,8 +28,8 @@ void enQueue(SeqQueue &q, int e) {
cout << "此队列已满" << endl; cout << "此队列已满" << endl;
return; return;
} }
q.rear = (q.rear + 1) % MAX_SIZE;
q.data[q.rear] = e; q.data[q.rear] = e;
q.rear = (q.rear + 1) % MAX_SIZE;
} }
int deQueue(SeqQueue &q) { int deQueue(SeqQueue &q) {
@@ -37,6 +37,7 @@ int deQueue(SeqQueue &q) {
cout << "此队列为空" << endl; cout << "此队列为空" << endl;
return NULL; return NULL;
} }
return q.data[q.front]; int returnE = q.data[q.front];
q.front(q.front - 1) % MAX_SIZE; q.front = (q.front + 1) % MAX_SIZE;
return returnE;
} }
+17
View File
@@ -1,8 +1,25 @@
//test2.cpp //test2.cpp
#include<iostream> #include<iostream>
#include"SeqQueue.h" //SeqQueue类见第三问
using namespace std; using namespace std;
int main() { 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; return 0;
} }