1、队列介绍
它与栈刚好相反,是一种先进先出的线性表,它有两个端口添加、删除元素,一个端口只能添加元素,被称为入队,该端口被为队尾,另一个端口只能删除,被称为出队,该端口被称为队头。
2、队列结构所具备的功能
1、创建队列
2、销毁队列
3、队列是否为空
4、队列是否为满
5、入队
6、出队
8、查看队头元素
9、查看队尾元素
10、队列元素数量
注:只有顺序栈结构才有需要判断队列是否满。
3、队列结构的链式表示与实现
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define TYPE int
typedef struct Node
{
TYPE data;
struct Node* next;
}Node;
Node* create_node(TYPE data)
{
Node* node = malloc(sizeof(Node));
node->data = data;
node->next = NULL;
return node;
}
typedef struct QueueList
{
Node* front;
Node* rear;
}QueueList;
// 创建队列
QueueList* create_queue(void)
{
QueueList* queue = malloc(sizeof(QueueList));
queue->front = NULL;
queue->rear