#include<iostream>
using namespace std;
/*头结点指向第一个空QNode*/
typedef struct QNode//数据结构
{
int data;
struct QNode *next;
}QNode,*Queueptr;
typedef struct//操作
{
Queueptr front;
Queueptr rear;
}LinkQueue;
bool InitQueue(LinkQueue &q)
{
if (!(q.front = q.rear = (Queueptr)malloc(sizeof(QNode))))return false;
q.front->next = NULL;
return true;
}
bool DestroyQueue(LinkQueue &q)
{
while (q.front)
{
q.rear = q.front->next;
free(q.front);
q.front = q.rear;
}
return true;
}
bool QueueEmpty(LinkQueue q)
{
if (q.rear == q.front)return true;
return false;
}
int QueueLength(LinkQueue q)
{
return (q.rear - q.front);
}
bool GetHead(LinkQueue q, int &e)
{
if (q.front == q.rear)return false;
e = q.front->next->data;
return true;
}
bool EnQueue(LinkQueue &q, int e)
//插入e为新的队尾
{
Queueptr p = (Queueptr)malloc(sizeof(QNode));
p->data = e; p->next = NULL;
q.rear->next = p;
q.rear = p;
return true;
}
bool Dequeue(LinkQueue&q, int &e)
//删除对头元素,并用e返回其值
{
if (q.front == q.rear)return false;
e = q.front->next->data;
if (q.front->next = q.rear)
{
free(q.rear);
q.rear = q.front;
}
else
{
Queueptr p = q.front->next->next;
free(q.front->next);
q.front->next = p;
}
return false;
}
int main()
{
}