//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 100
#define ERROR 0
#define OK 1
typedef int SElemType;
typedef int Status;

typedef int QElemType;
//节点结构
typedef struct QNode
{
QElemType data;
struct QNode* next;
}QNode, * QueuePtr;
//队列结构
typedef struct
{
//定义了头节点和尾节点
QueuePtr front, rear;
}LinkQueue;
//入队
Status EnQueue(LinkQueue* s, QElemType e)
{
QueuePtr temp = (QueuePtr)malloc(sizeof(QNode));
//给要入队的数据申请内存
if (temp == NULL)
{
return ERROR;
}
//给新要入队申请内存的结构体赋值
temp->data = e;
temp->next = NULL;
//将结构体入队
s->rear->next = temp;
//将尾指针指向新入队的结构体
s->rear = temp;
return OK;
}
//出队
Status DeQueue(LinkQueue* s, QElemType *e)
{
//判断队列是否为空
if (s->front == s->rear)
{
return ERROR;
}
//建立临时节点指针
QueuePtr temp;
//给临时节点指针赋值
temp = s->front->next;
//给需要出队的内容赋值
*e = temp->data;
//偏移头指针指向的位置
s->front->next = temp->next;
if (s->rear == temp)//如果要出队的数据是尾节点指向的地址
{
//那么说明一个一个数据在队里,这个时候需要吧
//头节点和尾节点的指向指向在一起
s->rear = s->front;
}
free(temp);
temp = NULL;
return OK;
}