当前位置: 首页 > news >正文

做最精彩的绳艺网站登陆网站取消备案

做最精彩的绳艺网站,登陆网站取消备案,专做轮胎的网站,九宫格网站模板一.队列的概念及结构 队列#xff1a;只允许在一端进行插入数据操作#xff0c;在另一端进行删除数据操作的特殊线性表#xff0c;队列具有 先进先出 FIFO(First In First Out) 入队列#xff1a;进行插入操作的一端称为 队尾 出队列#xff1a;进行删除操作的一端称为… 一.队列的概念及结构 队列只允许在一端进行插入数据操作在另一端进行删除数据操作的特殊线性表队列具有 先进先出 FIFO(First In First Out) 入队列进行插入操作的一端称为 队尾 出队列进行删除操作的一端称为 队头 二.队列的实现 关于队列的实现既可以用数组也可以用链表所以我们对比两者优劣 数组实现出队列在数组头上出数据这样每次都要覆盖效率会比较低。 因此我们用链表实现单链表 下面我们来进行实现 第一步定义结构体 //定义结构体 typedef int QDataType; typedef struct QueueNode {QDataType date;struct QueueNode* next; }QNode; typedef struct Queue {QNode* head;QNode* tail; }Queue; 第二步队列初始化 //队列初始化定义 void QueueInit(Queue* ps) {//判断assert(ps);//将head和tail置空ps-head ps-tail NULL; } 第三步对头出队列和对尾入队列 // 队头出队列定义 void QueuePop(Queue* ps) {//判断assert(ps);assert(ps-head);//头队列也不能为空//判断是否一个节点if (ps-head-next NULL){free(ps-head);ps-head ps-tail NULL;}else{//当不为一个节点QNode* next ps-head-next;free(ps-head);ps-head next;} } //队尾入队列定义 void QueuePush(Queue* ps, QDataType x) {//判断assert(ps);//开辟空间放进队列中QNode* newnode (QNode*)malloc(sizeof(QNode));//判断开辟成功否if (newnode NULL){perror(newnode);exit(-1);}newnode-date x;newnode-next NULL;//判断head和tail是否指向NULLif (ps-tail NULL){//将两指针都指向newnodeps-head ps-tail newnode;}//如果tail不指向空else{ps-tail-next newnode;ps-tail newnode;} } 第四步队列头部元素和队列尾部元素 // 获取队列头部元素定义 QDataType QueueFront(Queue* ps) {assert(ps);assert(ps-head);return ps-head-date; } // 获取队列队尾元素定义 QDataType QueueBack(Queue* ps) {assert(ps);assert(ps-tail);return ps-tail-date; } 第五步实现一些特殊接口 // 检测队列是否为空定义 bool QueueEmpty(Queue* ps) {//判断assert(ps);return ps-head NULL;//判断真假 } // 获取队列中有效元素个数定义 int QueueSize(Queue* ps) {assert(ps);int size 0;QNode* cur ps-head;while (cur){cur cur-next;size;}return size; } 第六步销毁队列接口 // 销毁队列 void QueueDestroy(Queue* ps) {assert(ps);QNode* cur ps-head;while (cur){QNode* next cur-next;free(cur);cur next;} } 三.测试代码 #include Queue.h void test() {Queue s;//队列初始化调用QueueInit(s);//队尾入队列调用QueuePush(s, 1);QueuePush(s, 2);QueuePush(s, 3);QueuePush(s, 4);QueuePush(s, 5);QueuePush(s, 6);QueuePop(s);// 队头出队列调用QueuePush(s, 7);printf(%d\n, QueueBack(s));QueuePush(s, 8);QueuePush(s, 9);int ret QueueSize(s);printf(size%d\n, ret);while (!QueueEmpty(s)){printf(%d ,QueueFront(s));QueuePop(s);// 队头出队列调用}printf(\n);int ret2QueueSize(s);printf(size%d\n, ret2);QueueDestroy(s); } int main() {test();return 0; } 结果 小编测试是没有问题的当然不保证一定没错有问题欢迎指正。 四.代码 头文件和实现文件 #pragma once #include stdio.h #include assert.h #include stdlib.h #include stdbool.h //定义结构体 typedef int QDataType; typedef struct QueueNode {QDataType date;struct QueueNode* next; }QNode; typedef struct Queue {QNode* head;QNode* tail; }Queue; //队列初始化声明 void QueueInit(Queue* ps); //队尾入队列声明 void QueuePush(Queue* ps, QDataType x); // 队头出队列声明 void QueuePop(Queue* ps); // 检测队列是否为空声明 bool QueueEmpty(Queue* ps); // 获取队列头部元素声明 QDataType QueueFront(Queue* ps); // 获取队列队尾元素声明 QDataType QueueBack(Queue* ps); // 获取队列中有效元素个数声明 int QueueSize(Queue* ps); // 销毁队列声明 void QueueDestroy(Queue* ps); #include Queue.h//队列初始化定义 void QueueInit(Queue* ps) {//判断assert(ps);//将head和tail置空ps-head ps-tail NULL; } //队尾入队列定义 void QueuePush(Queue* ps, QDataType x) {//判断assert(ps);//开辟空间放进队列中QNode* newnode (QNode*)malloc(sizeof(QNode));//判断开辟成功否if (newnode NULL){perror(newnode);exit(-1);}newnode-date x;newnode-next NULL;//判断head和tail是否指向NULLif (ps-tail NULL){//将两指针都指向newnodeps-head ps-tail newnode;}//如果tail不指向空else{ps-tail-next newnode;ps-tail newnode;} } // 队头出队列定义 void QueuePop(Queue* ps) {//判断assert(ps);assert(ps-head);//头队列也不能为空//判断是否一个节点if (ps-head-next NULL){free(ps-head);ps-head ps-tail NULL;}else{//当不为一个节点QNode* next ps-head-next;free(ps-head);ps-head next;} } // 检测队列是否为空定义 bool QueueEmpty(Queue* ps) {//判断assert(ps);return ps-head NULL;//判断真假 } // 获取队列头部元素定义 QDataType QueueFront(Queue* ps) {assert(ps);assert(ps-head);return ps-head-date; } // 获取队列队尾元素定义 QDataType QueueBack(Queue* ps) {assert(ps);assert(ps-tail);return ps-tail-date; } // 获取队列中有效元素个数定义 int QueueSize(Queue* ps) {assert(ps);int size 0;QNode* cur ps-head;while (cur){cur cur-next;size;}return size; } // 销毁队列 void QueueDestroy(Queue* ps) {assert(ps);QNode* cur ps-head;while (cur){QNode* next cur-next;free(cur);cur next;} } 测试文件 #include Queue.h void test() {Queue s;//队列初始化调用QueueInit(s);//队尾入队列调用QueuePush(s, 1);QueuePush(s, 2);QueuePush(s, 3);QueuePush(s, 4);QueuePush(s, 5);QueuePush(s, 6);QueuePop(s);// 队头出队列调用QueuePush(s, 7);printf(%d\n, QueueBack(s));QueuePush(s, 8);QueuePush(s, 9);int ret QueueSize(s);printf(size%d\n, ret);while (!QueueEmpty(s)){printf(%d ,QueueFront(s));QueuePop(s);// 队头出队列调用}printf(\n);int ret2QueueSize(s);printf(size%d\n, ret2);QueueDestroy(s); } int main() {test();return 0; } 最后感谢大家的支持小编一定会继续努力的
http://www.pierceye.com/news/40355/

相关文章:

  • 男女激烈做羞羞事网站网站韩剧大气wordpress主题
  • 网站做端口是什么情况佛山建站佛山网页设计
  • 移动论坛网站模板乐陵seo排名
  • 潍柴新建站登录网址响应式网站多少钱
  • 广州中企动力网站制作外链查询工具
  • 小城镇建设的网站文献数据做图网站有哪些内容
  • 重庆做网站及优化报价榆林市 网站建设
  • 滨江网站制作没有备案的网站 推广
  • 自考都到哪个网站找题做wordpress后台产品图标
  • 中国大唐集团公司招聘网站页面优化
  • 搭建一个网站教程工作室注册
  • 域名购买成功后网站怎么建设WordPress文章图片自动圆角
  • 网站开发项目描述范文合肥做网站好的公司
  • 如何建网站老鱼网网站建设经费预算
  • 泰达建设集团网站建设网站需要买什么
  • 哈尔滨网站优化排名地产网站建设互动营销
  • 做网站需要多少钱济宁网站外链建设的15个小技巧
  • 株洲网站排名优化价格wordpress和织梦百度收录
  • 城市管理如何宣传市建设网站微软网站做u盘启动教程
  • 建设银行啦卡信用网站广东省住房和城乡建设部网站
  • 多举措加强局门户网站建设上海网站建设千元漂亮
  • 360免费建站网页链接网站制作课程介绍
  • 顶客网站和网摘网站手机网站大全免费下载
  • 网站设计与制作说明书大连开发区规划建设局网站
  • 通辽网站建设tlyltd网站设计公司简介
  • 网站开发从哪里学起php创建wordpress
  • 门户网站集群建设方案网站维护 网站后台建设知识
  • 定远县建设小学网站最新域名网站
  • 杭州网站制作公司网站建设特定开发
  • 设计logo网站免费奇米关键词搜索站长工具