include[HTML_REMOVED]
define MAX_SIZE 100
using namespace std;
typedef struct {
int data[MAX_SIZE];
int front;
int end;
}SeqQueue;
bool isEmpty(SeqQueue* queue) {
return queue -> front == queue -> end;
}
void initQueue(SeqQueue* queue) {
queue -> front = 0;
queue -> end = 0;
}
void destoryQueue(SeqQueue* queue) {
queue -> front = 0;
queue -> end = 0;
}
void clearQueue(SeqQueue* queue) {
queue -> front = 0;
queue -> end = 0;
}
void printQueue(SeqQueue* queue) {
if (isEmpty(queue)) {
cout << “队列为空” << endl;
return ;
}
cout << “队列中的元素:”;
int i = queue -> front;
while (i != queue -> end) {
cout << i << ‘ ‘;
i = (i + 1) % MAX_SIZE;
}
cout << endl;
}
int size(SeqQueue* queue) {
return (queue -> end - queue -> front + MAX_SIZE) % MAX_SIZE;
}
bool getFront(SeqQueue* queue, int& value) {
if (isEmpty(queue)) {
return false;
}
value = queue -> data[queue -> front];
return true;
}
bool deleteQueue(SeqQueue* queue, int &value) {
if (isEmpty(queue)) {
return false;
}
value = queue -> data[queue -> front];
queue -> front = (queue -> front + 1) % MAX_SIZE;
return true;
}
bool insertQueue(SeqQueue queue, int value) {
if (queue -> end + 1 % MAX_SIZE == queue -> front) {
return false;
}
queue -> data[queue -> end] = value;
queue -> end = (queue -> end + 1) % MAX_SIZE;
return true;
}
int main () {
SeqQueue seq = new SeqQueue;
initQueue(seq);
int n;
cin >> n;
for (int i = 0; i < n; i ++) {
insertQueue(seq, i);
}
cout << size(seq) << endl;
printQueue(seq);
int value = -1;
getFront(seq, value);
cout << value << endl;
value = -1;
deleteQueue(seq, value);
cout << value << endl;
printQueue(seq);
clearQueue(seq);
printQueue(seq);
return 0;
}