#include
#include
typedef int QElemType;
typedef int Status;
typedef struct QNode {
QElemType data;
struct QNode *next;
}QNode,*QueuePtr;
typedef struct {
QueuePtr front;
QueuePtr rear;
}LinkQueue;
Status InitQueue(LinkQueue *Q)
{
Q->front=Q->rear=(QueuePtr)malloc(sizeof(QNode));
if(!Q->front)exit(0);
Q->front=NULL;
return 1;
}
Status EnQueue(LinkQueue *Q,QElemType e)
{
QueuePtr p;
p=(QueuePtr)malloc(sizeof(QNode));
p->data=e;
p->next=NULL;
Q->rear->next=p;
Q->rear=p;
return 1;
}
Status Dequeue(LinkQueue *Q,QElemType *e)
{
QueuePtr p;
p=Q->front->next;
*e=p->data;
Q->front->next=p->next;
if(Q->rear==p)Q->rear=Q->front;
free(p);
return 1;
}
Status DestroyQueue(LinkQueue *Q)
{
while(Q->front){
Q->rear=Q->front->next;
free(Q->front);
Q->front=Q->rear;
}
return 1;
}
void main()
{
int i,e;
LinkQueue Q;
InitQueue(&Q);
for(i=0;i<10;i++)
{
EnQueue(&Q,i);
}
for(i=0;i<8;i++)
{
Dequeue(&Q,&e);
printf("%d\t",e);
}
DestroyQueue(&Q);
system("pause");
}