typedef int QElemType;
typedef struct QNode
{
QElemType data;
QNode *next;
}QNode,*QueuePtr;
typedef struct
{
QueuePtr Front;
QueuePtr Rear;
}LinkQueue;
bool InitQueue(LinkQueue &Q)
{
Q.Front = Q.Rear = new QNode;
Q.Front->next = NULL;
return OK;
}
bool EnQueue(LinkQueue &Q,QElemType e)
{
QNode *p = new QNode;
p->data = e;
p->next = NULL;
Q.Rear->next = p;
Q.Rear = p;
return OK;
}
bool DeQueue(LinkQueue &Q,QElemType &e)
{
if(Q.Front == Q.Rear) return ERROR;
QNode p = Q.Front->next;
e = p->data;
Q.Front ->next = p->next;
if(Q.Rear == p) Q.Rear = Q.Front;
delete p;
return OK;
}
QElemType GetHead(LinkQueue Q)
{
if(Q.Front != Q.Rear)
return Q.Front->next->data;
}