//代码为测试,仅供参考
#include <stdio.h>
#include <stdlib.h>#define Status int
#define TRUE 1
#define FALSE 0
#define MAXSIZE 10
typedef int QElemType;
typedef struct
{
QElemType data[MAXSIZE];
int front;
int rear;
}sqQueue;
//初始化 循环队列
Status InitQueue(sqQueue *Q)
{
Q->font = Q->rear;
return TRUE;
}
Status ClearQueue(sqQueue *Q)
{
Q->font = Q->rear;
return TRUE;
}
Status QueueEmpty(Q)
{
if(Q.front == Q.rear)
{
return TRUE;
}
else
{
return FALSE
}
}
Status GetHead(sqQueue Q)
{
if(Q && Q.front != Q.rear)
{
return Q.data[Q.front];
}
return 0;
}
//求循环队列的长度
Status QueueLength(sqQueue Q)
{
return ((Q.rear - Q.front + MAXSIZE)%MAXSIZE);
}
//循环队列的入队:若队列未满,则插入元素e为Q的新队尾元素
Status EnQueue(sqQueue *Q,QElemType e)
{
if ((Q->rear + 1)%MAXSIZE == Q->front)
{
return FALSE;
}
Q->data[Q->rear] = e;
Q->rear = (Q->rear + 1)%MAXSIZE;
return TRUE;
}
//循环队列的出队列:若队列不为空,则删除队列Q的队头元素,用e返回其值
Status DeQueue(sqQueue *Q,QElemType *e)
{
if(Q->front = Q->rear)
{
return FALSE;
}
*e = Q->data[Q->front];
Q->ftont = (Q->front + 1)%MAXSIZE;
return TRUE;
}
void visit(QElemType e)
{
printf("%d\n",e);
}
Status TraverseQueue(Queue Q)
{
int i;
if(Q.front != Q.rear)
{
for(i=0;i<QueueLength(Q);i++)
{
visit(Q.data[(Q.front+i)%MAXSIZE]);
}
return TRUE;
}
return FALSE;
}
int main(int argc ,char *argv[])
{
return 0;
}