#include<iostream>
#include<cstdio>
using namespace std;
#define MAXSIZE 100
typedef int Status;
typedef int Elem;
typedef struct QNode
{
/* data */
Elem data;
struct QNode *next;
}QNode, *QueuePtr;
typedef struct
{
QueuePtr front;
QueuePtr rear;
}LinkQueue;//这种写法让我想起了 定义结构体 然后定义类 在类里放结构体
Status InitQueue(LinkQueue &Q)
{
Q.front = Q.rear = new QNode;
Q.front->next = NULL; //头指针 空
return 1;
}
Status EnQueue_H(LinkQueue &Q, Elem e)
{
QNode *p = new QNode;
p->data = e;
p->next = NULL;
Q.rear->next = p;//队尾的结点指向 新节点p
Q.rear = p;//队尾为p
return 1;
}
Status DeQueue(LinkQueue &Q, Elem &e)
{
if (Q.rear == Q.front) return 0;
QNode *p = Q.front->next;
e = p->data;
Q.front->next = p->next; //其实就是往下走 当删除了
if (Q.rear == p) Q.rear = Q.front; //如果整个没了 那就尾巴指向头
delete p;
return 1;
}
Elem GetHead(LinkQueue &Q)
{
if (Q.front != Q.rear)
return Q.front->next->data;
return 0;
}
int main()
{
LinkQueue Q;
//1
InitQueue(Q);
//1
EnQueue_H(Q, 1);
cout << GetHead(Q);
//1
Elem e = 0;
DeQueue(Q, e);
cout << GetHead(Q);
return 1;
}