#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define OK 1
#define OVERFLOW -1
#define STACKINITSIZE 200
#define STACKINCREMENT 10
#define MAXSIZE 100
#define ERROR 0
typedef int Status;
typedef struct{
Status *data;
int front;
int rear;
} SeqQueue;
int InitQueue ( SeqQueue &Q ) {//构造空队列
Q.data=(Status*)malloc(MAXSIZE*sizeof(Status));
if(! Q.data) return ERROR;
Q.rear = Q.front = 0;
return OK;
}
int QueueEmpty ( SeqQueue &Q ) {
if (Q.rear == Q.front) return OK;
else return ERROR;
}
int QueueFull ( SeqQueue &Q ) {
if( (Q.rear+1) % MAXSIZE == Q.front) return OK;
else return ERROR;
}
int EnQueue ( SeqQueue &Q, Status x ) {
if ( QueueFull (Q) ) return ERROR;
Q.data[Q.rear] = x;
Q.rear = ( Q.rear+1) % MAXSIZE;
return OK;
}
int DeQueue ( SeqQueue &Q, char &x ) {
if ( QueueEmpty (Q) ) return ERROR;
x = Q.data[Q.front];
Q.front = ( Q.front+1) % MAXSIZE;
return OK;
}
int GetFront ( SeqQueue &Q, Status &x ) {
if ( QueueEmpty (Q) ) return ERROR;
x = Q.data[Q.front];
return OK;
}
int Lenqueue(SeqQueue &Q) // 求队Q中当前元素个数
{ int i=(Q.rear-Q.front+ MAXSIZE)%MAXSIZE;
return(i);
}