网站建设-丹东,新手如何做代理商,怎么在本地搭建网站,怎么注册网自己的网站目录
前言
已完成内容
循环队列实现
01-开发环境
02-文件布局 03-代码
01-主函数
02-头文件
03-QueueCommon.cpp
04-QueueFunction.cpp
结语 前言 此专栏包含408考研数据结构全部内容#xff0c;除其中使用到C引用外#xff0c;全为C语言代码。使用C引用主要是为了…目录
前言
已完成内容
循环队列实现
01-开发环境
02-文件布局 03-代码
01-主函数
02-头文件
03-QueueCommon.cpp
04-QueueFunction.cpp
结语 前言 此专栏包含408考研数据结构全部内容除其中使用到C引用外全为C语言代码。使用C引用主要是为了简化指针的使用避免二重指针的出现。
已完成内容
[数据结构]01-顺序表C语言实现_Chandni.的博客-CSDN博客
[数据结构]02-单链表C语言实现_Chandni.的博客-CSDN博客
[数据结构]03-栈C语言实现_Chandni.的博客-CSDN博客
循环队列实现
01-开发环境 语言C/C14 编译器MinGW64 集成开发环境CLion2022.1.3
02-文件布局 请在CLion集成开发环境中创建C可执行程序否则无法运行原因上面已解释。 03-代码
01-主函数 用于测试和初始化队列。
#include ./Head/QueueData.h
#include ./Source/QueueCommon.cpp
#include ./Source/QueueFunction.cppint main() {ArrayQueue Q;// 初始化InitializationQueue(Q);// 入队QueuePush(Q, 1);QueuePush(Q, 2);QueuePush(Q, 3);QueuePush(Q, 4);QueuePush(Q, 5);QueuePrint(Q);printf(---------------------\n);// 出队ElemType value;QueuePop(Q, value);printf(Queue Pop Value %d\n, value);QueuePop(Q, value);printf(Queue Pop Value %d\n, value);QueuePrint(Q);printf(---------------------\n);// 入队QueuePush(Q, 4);QueuePush(Q, 5);QueuePrint(Q);printf(---------------------\n);return 0;
}02-头文件 用于存储结构体和常量等。
//
// Created by 24955 on 2023-02-26.
//#ifndef INC_01_ARRAYQUEUE_QUEUEDATA_H
#define INC_01_ARRAYQUEUE_QUEUEDATA_H
// 头文件
#include Stdio.h// 常量
#define MaxSize 5
typedef int ElemType;// 结构体
typedef struct {ElemType data[MaxSize];int front, rear;
} ArrayQueue;
#endif //INC_01_ARRAYQUEUE_QUEUEDATA_H03-QueueCommon.cpp 用于存储公共函数以及队列的输出。
//
// Created by 24955 on 2023-02-26.
//
// 初始化队列
void InitializationQueue(ArrayQueue Queue) {/** 1. 初始化队列*/Queue.front 0;Queue.rear 0;
}// 判断队列是否为空
bool JudgeQueueEmpty(ArrayQueue Queue) {/** 1. 头指针和尾指针相等则队列为空* 2. 这里的指针加引号只是一种标识这样说方便理解*/if (Queue.front Queue.rear) {return true;} else {return false;}
}// 判断队列是否已满
bool JudgeQueueFull(ArrayQueue Queue) {/** 1. 尾指针1取模与头指针相等则满*/if ((Queue.rear 1) % MaxSize Queue.front) {return true;} else {return false;}
}// 输出队列元素
void QueuePrint(ArrayQueue Queue) {/** 1. 判断队列是否为空* 2. 若不为空则从头输出*/if (!JudgeQueueEmpty(Queue)) {while (Queue.front ! Queue.rear) {printf(%3d, Queue.data[Queue.front]);Queue.front (Queue.front 1) % MaxSize;}printf(\n);} else {printf(Queue Empty.\n);}
}
04-QueueFunction.cpp 用于存储入队、出队等函数。
//
// Created by 24955 on 2023-02-26.
//
// 入队
void QueuePush(ArrayQueue Queue, ElemType value) {/** 1. 判断队列是否已满* 2. 若不满则入队*/if (!JudgeQueueFull(Queue)) {Queue.data[Queue.rear] value;Queue.rear (Queue.rear 1) % MaxSize;} else {printf(Queue Full.\n);}
}// 出队
void QueuePop(ArrayQueue Queue, ElemType value) {/** 1. 判断队列是否已空* 2. 若非空则出队*/if (!JudgeQueueEmpty(Queue)) {value Queue.data[Queue.front];Queue.front (Queue.front 1) % MaxSize;} else {printf(Queue Empty.\n);}
}
结语 本章循环队列的实现形式为数组的实现形式循环队列还可以使用链表形式实现链表实现形式请关注本专栏下一章。 此博客主要用于408考研数据结构C语言实现记录内有不足可留言可讨论。