int Init_Queue(LinkQueue *Q)
{
Q=(LinkQueue*)malloc(sizeof(LinkQueue));
if(Q==NULL) return 0;
Q->front=(QueueNode*)malloc(sizeof(QueueNode));
if(Q->front==NULL) return 0;
Q->rear=(QueueNode*)malloc(sizeof(QueueNode));
if(Q->rear==NULL) return 0;
Q->front->next=head;
Q->rear->next=head;
k=1;
return 1;
}
int Empty_Queue(LinkQueue *Q)
{
if((Q->front->next==NULL)&&(Q->rear->next==NULL)&&(k=1))
return 1;
else return 0;
}
void EnQueue(LinkQueue *Q,int x)
{
QueueNode *q;
q=(QueueNode *)malloc(sizeof(QueueNode));
if(q==NULL) exit(0);
q->data=x;
if(Empty_Queue(Q)==1)
{
head=q;head->next=Q->rear->next;
}
else
{Q->rear->next=q;Q->rear=q;}
}
int DeQueue(LinkQueue *Q)
{
if(Empty_Queue(Q)==1) exit(0);
QueueNode *p;int x;
p=Q->front->next;x=p->data;
Q->front->next=p->next;
if(Q->rear==p)
{Q->front=Q->rear;}
return x;
}
int QueueFront(LinkQueue *Q)
{
int x;
if(Empty_Queue(Q)==1) exit(0);
x=Q->front->next->data;
return x;
}
int main()
{
LinkQueue *Q;
if(Init_Queue(Q)==1)
{
EnQueue(Q,1);
EnQueue(Q,2);
EnQueue(Q,3);DeQueue(Q);
EnQueue(Q,4);DeQueue(Q);
printf("QueueFront:%d\n",QueueFront(Q));
}
getch();
}
http://g.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=6424807aef50352ab1342d0e6373d7ca/e824b899a9014c0830d1a7680c7b02087af4f411.jpg