#include
#include
#define N 6
typedef int datatype;
typedef struct
{
datatype data[N];
int front; // points to the postion before the first element of queue
int rear; // points to the last element of queue
} sequeue;
sequeue *CreateEmptyQueue()
{
sequeue *sq;
sq = (sequeue *)malloc(sizeof(sequeue));
sq->front = sq->rear = 0;
return sq;
}
int EmptyQueue(sequeue *sq)
{
return (sq->front == sq->rear);
}
int FullQueue(sequeue *sq)
{
return (((sq->rear + 1) % N) == sq->front);
}
void ClearQueue(sequeue *sq)
{
sq->front = sq->rear;
}
void EnQueue(sequeue *sq, datatype x)
{
sq->rear = (sq->rear + 1) % N;
sq->data[sq->rear] = x;
return;
}
datatype DeQueue(sequeue *sq)
{
sq->front = (sq->front + 1) % N;
return sq->data[sq->front];
}
阅读(573) | 评论(0) | 转发(2) |