标签:
#include <stdio.h>
#include <stdlib.h>
typedef struct Qnode {
int val;
struct Qnode *next;
}Qnode, *pQnode;
typedef struct {
pQnode rear;
}Link;
void InitQueue(Link *Q)
{
(*Q).rear = (pQnode)malloc(sizeof(Qnode));
if((*Q).rear == NULL) exit(-1);
(*Q).rear->next = (*Q).rear;
}
bool EmptyQueue(Link Q)
{
if(Q.rear->next == Q.rear) return true;
return false;
}
void EnQueue(Link *Q, int x)
{
pQnode p = (pQnode)malloc(sizeof(Qnode));
if(!p) exit(-1);
p->val = x; p->next = NULL;
if(EmptyQueue(*Q)) {
(*Q).rear->next = p;
p->next = (*Q).rear;
}
(*Q).rear->next->next = p;
p->next = (*Q).rear;
}
void DeQueue(Link *Q, int *x)
{
if(EmptyQueue(*Q)) {
printf("The Queue has no member!\n");
return ;
}
pQnode p = (*Q).rear->next;
(*x) = p->val;
(*Q).rear->next = p->next;
free(p);
printf("%d Out\n", *x);
}
标签:
原文地址:http://blog.csdn.net/j_sure/article/details/44777781