1、定义
typedef struct LinkQueueNode
{
ElemType data;
struct LinkQueueNode *link;
}LinkQueueNode;
typedef struct LinkQueue
{
LinkQueueNode *head; // 队头指针
LinkQueueNode *tail; // 队尾指针
}LinkQueue;
2、初始化
void LinkQueueInit(LinkQueue *pq)
{
assert(pq != NULL);
pq->head = pq->tail = NULL;
}
3、入队、出队
void LinkQueueEn(LinkQueue *pq, ElemType x)
{
assert(pq != NULL);
LinkQueueNode *node = (LinkQueueNode*)malloc(sizeof(LinkQueueNode));
assert(node != NULL);
node->data = x;
node->link = NULL;
if (pq->head == NULL)
pq->head = pq->tail = node;
else
{
pq->tail->link = node;
pq->tail = node;
}
}
void LinkQueueDe(LinkQueue *pq)
{
assert(pq != NULL);
if (pq->head != NULL)
{
LinkQueueNode *p = pq->head;
if (pq->head == pq->tail)
pq->head = pq->tail = NULL;
el