#include
#include
typedef int datatype;
typedef struct _node_
{
datatype data;
struct _node_ *next;
} linknode, *linklist;
typedef struct
{
linklist front;
linklist rear;
} linkqueue;
linkqueue *CreateEmptyQueue()
{
linkqueue *lq;
lq = (linkqueue *)malloc(sizeof(linkqueue));
lq->front = lq->rear = (linklist)malloc(sizeof(linknode));
lq->front->next = NULL;
return lq;
}
int EmptyQueue(linkqueue *lq)
{
return (lq->front == lq->rear);
}
void EnQueue(linkqueue *lq, datatype x)
{
lq->rear->next = (linklist)malloc(sizeof(linknode));
lq->rear = lq->rear->next;
lq->rear->data = x;
lq->rear->next = NULL;
return;
}
datatype DeQueue(linkqueue *lq)
{
linklist q;
q = lq->front;
lq->front = q->next;
free(q);
return (lq->front->data);
}
void ClearQueue(linkqueue *lq)
{
linklist q;
while (lq->front != lq->rear)
{
q = lq->front;
lq->front = q->next;
free(q);
}
return;
}
阅读(933) | 评论(0) | 转发(0) |