#include<stdio.h>
#define MAXSIZE 100
typedef int datatype;
typedef struct node
{
datatype data[MAXSIZE+1];
int rear,head;
}sequeue;
sequeue *sq,SQ;
void CIR_INITQUEUE(sequeue *sq)
{
sq->head=MAXSIZE-1;
sq->rear=MAXSIZE-1;
printf("初始化成功\n");
}
int CIR_EMPTY(sequeue *sq)
{
if(sq->rear==sq->head)
return 1;
else return 0;
}
int CIR_GETFRONT(sequeue *sq)//取出循环队列的队头元素 (位置)
{
if(CIR_EMPTY(sq))
{
printf("队列为空不能执行出队运算");
return 0;
}
else
{
return((sq->head+1)%MAXSIZE);
}
}
int CIR_ENQUEUE(sequeue *sq,datatype x) //循环队列的入队运算
{
if(sq->head==(sq->rear+1)%MAXSIZE)
{
printf("队列已满");
return 0;
}
else
{
sq->rear=(sq->rear+1)%MAXSIZE;
sq->data[sq->rear]=x;
return 1;
}
}
datatype CIR_DEQUEUE(sequeue *sq)
{
if(CIR_EMPTY(sq))
{
printf("队列为空");
return 0;
}
else
{ sq->head=(sq->head+1)%MAXSIZE;
printf("%d",sq->data[sq->head]);
return (sq->data[sq->head]);
}
}
int main()
{sq=&SQ;
datatype x=5;
void CIR_INITQUEUE(sequeue *sq);
int CIR_EMPTY(sequeue *sq);
int CIR_GETFRONT(sequeue *sq);
int CIR_ENQUEUE(sequeue *sq,datatype x);
datatype CIR_DEQUEUE(sequeue *sq);
CIR_INITQUEUE(&SQ);
scanf("%d",&x);
CIR_ENQUEUE(&SQ,x);
CIR_DEQUEUE(&SQ);
return 0;
}