#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node *next;
}queue;
typedef struct
{
queue *front;
queue *rear;
}LinkQueue;
void Init(LinkQueue *p) //初始化队列
{
queue *phead = (queue *)malloc(sizeof(queue));
p->front = p->rear = phead;
p->front->next = NULL;
}
int isEmpty(LinkQueue *p) //判断是否为空队列
{
if(p->front->next == NULL)
return 1;
else
return 0;
}
int Enter(LinkQueue *p, int x) //入队
{
queue *t = (queue *)malloc(sizeof(queue));
t->data = x;
t->next = NULL;
p->rear->next = t;
p->rear = t;
}
int Delet(LinkQueue *p, int *px) //出队
{
if(isEmpty(p))
return 0;
else{
queue *t = p->front->next;
*px = t->data;
p->front->next = t->next;
free(t);
return 1;
}
}
链式队列的实现
最新推荐文章于 2022-07-21 08:30:00 发布