#include <stdio.h>
#include <stdlib.h>
#define maxsize 100
typedef int ElemType;
typedef struct {
ElemType *base;
int front;
int rear;
}SqQueue;
int InitQueue(SqQueue& S) {
S.base = (ElemType*)malloc(maxsize * sizeof(ElemType));
if (!S.base)return 0;
S.front = S.rear = 0;
return 1;
}
int QueueLength(SqQueue Q) {
return ((Q.rear - Q.front + maxsize) % maxsize);
}
int EnQueue(SqQueue& s, ElemType x) {
if (s.front == (s.rear+1)%maxsize)return 0;
s.base[s.rear] = x;
s.rear = (s.rear + 1) % maxsize;
return 1;
}
int DeQueue(SqQueue& s, ElemType& x) {
if (s.front == s.rear)return 0;
x = s.base[s.front];
s.front = (s.front + 1) % maxsize;
return 1;
}
int SqQueneEmpty(SqQueue& s) {
if (s.front == s.rear)return 1;
return 0;
}
ElemType GetHead(SqQueue Q) {
if (Q.front != Q.rear)return Q.base[Q.front];
}