#include<stdlib.h>
typedef struct Node
{
int data;
struct Node *next;
}Node;
typedef struct
{
Node * front;
Node * rear;
}Queue;
void InitQueue(Queue &Q)
{
Node *p=(Node*)malloc(sizeof(Node));
p->next = NULL;
Q.front = p;
Q.rear=p;
}
int QueueEmpty(Queue Q)
{
return Q.rear==Q.front ? 1 : 0;
}
void EnQueue(Queue &Q, int e)
{
Node *p=(Node*)malloc(sizeof(Node));
p->data = e;
p->next =NULL;
Q.rear->next = p;
Q.rear = p;
}
{
Node *p=Q.front->next;
while(NULL !=p)
{
printf("%d\n",p->data);
p=p->next;
}
}
{
Node *p=Q.front->next;
if(Q.front == Q.rear)
{
return 0;
}
e = p->data;
Q.front->next = p->next;
if(Q.rear==p)
{
Q.rear = Q.front;
}
free(p);
return 1;
}
{
const int N = 10;
int i;
int e;
Queue Q;
InitQueue(Q);
for(i=0;i<N;++i)
{
EnQueue(Q,i);
}
for(i=0;i<N;++i)
{
DeQueue(Q,e);
printf("data[%d]=%d\n",i,e);
}
system("pause");
return 0;
}