完成循环链表类
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
//SeqQueue.cpp
|
||||
|
||||
#include "SeqQueue.h"
|
||||
#include<iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user