#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#define OK 1
#define ERROR 0
typedef int Status;
typedef int QElemType;
using namespace std;
typedef struct QNode //结点结构
{
QElemType data;
struct QNode *next;
}QNode,*QueuePtr;
typedef struct //队列的链表结构
{
QueuePtr front, rear;//队头、队尾指针
}LinkQueue;
//队列的初始化
Status InitQueue(LinkQueue &Q)
{
Q.front = Q.rear = (QueuePtr)malloc(sizeof(QNode));
if (!Q.front) return ERROR;
Q.front->next = NULL;
return OK;
}
//入队操作
Status EnQueue(LinkQueue &Q, QElemType e)
{
QueuePtr p = (QueuePtr)malloc(sizeof(QNode));
if (!p)//若内存分配失败
return ERROR;
p->data = e;
p->next = NULL;
Q.rear->next = p;
Q.rear = p;
return OK;
}
//出队操作,将出队的数据存储到e中
Status DeQueue(LinkQueue &Q, QElemType &e)
{
QueuePtr p;
if (Q.front == Q.rear) return ERROR;
p = Q.front->next;
e = p->data;
Q.front->next =
链队列的初始化、入队、出队及打印(数据结构)
最新推荐文章于 2022-12-26 14:47:43 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)