#include<stdio.h>
#include<stdlib.h>
typedef signed char Status;
//define queue node struct
typedef struct QNode
{
int data;
struct QNode *next;
}QNode,*QueuePtr;
define front queue node and rear queue node
typedef struct
{
QueuePtr front;
QueuePtr rear;
}LinkQueue;
//initial queue as empty
void InitQueue(LinkQueue &Q)
{
Q.rear =Q.front=(QueuePtr)malloc(sizeof(QNode));
if(!Q.front) exit(1);
Q.front->next=NULL;
}
//destroy queue
Status DesteryQueue(LinkQueue &Q)
{
while(Q.front)
{
Q.rear=Q.front->next;
free(Q.front);
Q.front=Q.rear;
}
return 0;
}
//insert queue node from as rear
Status InsertQuene(LinkQueue &Q,int e)
{
QueuePtr p=0;
p = (QueuePtr)malloc(sizeof(QNode));
if(!p) exit(1);
p->next = NULL;
p->data = e;
Q.rear->next = p;
Q.rear = p;
return 0;
}
//delete queue node from front
Status DeleteQueue(LinkQueue &Q, int &e)
{
if(Q.rear == Q.front) return -1;
QueuePtr p=0;
p = Q.front->next;
e = p->data;
Q.front->next = p->next;
if(Q.rear == p) Q.rear = Q.front;
free(p);
return 0;
}