Chinaunix首页 | 论坛 | 博客
  • 博客访问: 847814
  • 博文数量: 156
  • 博客积分: 6553
  • 博客等级: 准将
  • 技术积分: 3965
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-22 18:36
文章存档

2012年(3)

2011年(43)

2010年(110)

分类: C/C++

2010-10-03 16:20:09

#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;
}

阅读(590) | 评论(0) | 转发(3) |
给主人留下些什么吧!~~