43 lines
740 B
C++
43 lines
740 B
C++
//SeqQueue.cpp
|
|
|
|
#include "SeqQueue.h"
|
|
#include<iostream>
|
|
|
|
using namespace std;
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|