#include<iostream>
using namespace std;
typedef int datatype;
const int maxsize = 100;
typedef struct node {
datatype data[maxsize];
int front, rear;
}sqqueue;
void init_sqqueue(sqqueue* lq) {
lq->front = lq->rear = 0;
cout << "创建队列成功" << endl;
}
int en_sqqueue(sqqueue* lq, datatype x) {
if ((lq->rear + 1) % maxsize == lq->front) {
cout << "队满,无法入队" << endl;
return 0;
}
lq->rear = (lq->rear + 1) % maxsize;
lq->data[lq->rear] = x;
cout << "入队元素为" << x << endl;
return 1;
}
int de_sqqueue(sqqueue* lq, datatype* x) {
if (lq->front == lq->rear) {
cout << "队列为空" << endl;
return 0;
}
lq->front = (lq->front + 1) % maxsize;
*x = lq->data[lq->front];
cout << "出队元素为" << *x << endl;
return 1;
}
int empty_sqqueue(sqqueue* lq) {
if (lq->front == lq->rear) {
cout << "队空" << endl;
return 1;
}
else {
cout << "队不空" << endl;
return 0;
}
}
int main() {
sqqueue* lq;
datatype* x;
x = new datatype;
lq = new sqqueue;
init_sqqueue(lq);
empty_sqqueue(lq);
en_sqqueue(lq, 100);
en_sqqueue(lq, 200);
empty_sqqueue(lq);
de_sqqueue(lq, x);
de_sqqueue(lq, x);
empty_sqqueue(lq);
return 0;
}