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

青岛网站建设公司大全宁波靠谱营销型网站建设

青岛网站建设公司大全,宁波靠谱营销型网站建设,软件技术是干嘛的,莱芜哪家企业做网站文章目录 🐸一、队列的概念及结构🍄1、队列的概念定义🍄2、动图演示 🐸二、队列的实现🐸三、链表结构队列详解🍎创建队列的结构⭕接口1:定义结构体(QNode、Queue)⭕接口2…

在这里插入图片描述

文章目录

  • 🐸一、队列的概念及结构
    • 🍄1、队列的概念定义
    • 🍄2、动图演示
  • 🐸二、队列的实现
  • 🐸三、链表结构队列详解
    • 🍎创建队列的结构
    • ⭕接口1:定义结构体(QNode、Queue)
    • ⭕接口2:初始化(QueueInit)
    • ⭕接口3:销毁(QueueDestroy)
    • ⭕接口4:入队列(QueuePush)
    • ⭕接口5:出队列(QueuePop)
    • ⭕接口6:取队头数据(QueueFront)
    • ⭕接口7:取队尾数据(QueueBack)
    • ⭕接口8:获取队列大小(QueueSize)
    • ⭕接口9:判空(QueueEmpty)
  • 🐸四、完整代码
    • 🥝Queue.h
    • 🥝Queue.c
    • 🥝Test.c

在这里插入图片描述

🐸一、队列的概念及结构

🍄1、队列的概念定义

队列:只允许在一端进行插入数据操作,在另一端进行删除数据操作的特殊线性表,队列具有先进先出FIFO(First In First Out) 入队列:进行插入操作的一端称为队尾 出队列:进行删除操作的一端称为队头

  • 入队列:进行插入操作的一端称为队尾
  • 出队列:进行删除操作的一端称为队头

🍄2、动图演示

在这里插入图片描述

在这里插入图片描述

🌰可以想象成排队去食堂打饭,前面先打完饭的就从队头先走了,后来的就需要在后面队尾继续排队

🐸二、队列的实现

队列也可以数组和链表的结构实现,使用链表的结构实现更优一些,因为如果使用数组的结构,出队列在数组头上出数据,效率会比较低。

🐸三、链表结构队列详解

在这里插入图片描述

🍎创建队列的结构

🥰这里先创建三个文件:
1️⃣:Queue.h文件用于函数的声明
2️⃣:Queue.c文件用于函数的定义
3️⃣:Test.c文件用于测试函数
建立三个文件的目的: 将队列作为一个项目来进行编写,方便我们的学习与观察。

⭕接口1:定义结构体(QNode、Queue)

🚩这里需要定义两个结构体:QNode、Queue,分别表示:队列链表每个节点结构和整个队列链表结构

🥰请看代码与注释👇

//自定义类型
typedef int QDataType;//队列链表每个节点结构
typedef struct QueueNode
{struct QueueNode* next;QDataType data;
}QNode;//整个队列链表结构
typedef struct Queue
{QNode* phead;QNode* ptail;int size;
}Queue;

⭕接口2:初始化(QueueInit)

🥰请看代码与注释👇

//初始化
void QueueInit(Queue* pq)
{//断言传入指针不为NULLassert(pq);pq->phead = NULL;pq->ptail = NULL;pq->size = 0;
}

⭕接口3:销毁(QueueDestroy)

🥰请看代码与注释👇

//销毁
void QueueDestroy(Queue* pq)
{//断言传入指针不为NULLassert(pq);QNode* cur = pq->phead;while (cur){QNode* next = cur->next;free(cur); //释放cur = next;}pq->phead = pq->ptail = NULL;pq->size = 0;
}

⭕接口4:入队列(QueuePush)

🥰请看代码与注释👇

//入队列
void QueuePush(Queue* pq, QDataType x)
{assert(pq);QNode* newnode = (QNode*)malloc(sizeof(QNode));if (newnode == NULL){perror("malloc fail\n");return;}newnode->data = x;newnode->next = NULL;if (pq->ptail == NULL) //如果没有节点(空队列){assert(pq->phead == NULL);pq->phead = pq->ptail = newnode;}else //非空队列{pq->ptail->next = newnode;pq->ptail = newnode;}pq->size++;
}

⭕接口5:出队列(QueuePop)

🥰请看代码与注释👇

//出队列
void QueuePop(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));//1、一个节点if (pq->phead->next == NULL){free(pq->phead);pq->phead = pq->ptail = NULL;}//2、多个节点else{//头删QNode* next = pq->phead->next;free(pq->phead);pq->phead = next;}pq->size--;
}

⭕接口6:取队头数据(QueueFront)

🥰请看代码与注释👇

//获取队头数据
QDataType QueueFront(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->phead->data;
}

⭕接口7:取队尾数据(QueueBack)

🥰请看代码与注释👇

//获取队尾数据
QDataType QueueBack(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->ptail->data;
}

⭕接口8:获取队列大小(QueueSize)

🥰请看代码与注释👇

//获取队列大小
int QueueSize(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->size;
}

⭕接口9:判空(QueueEmpty)

🥰请看代码与注释👇

//判空
bool QueueEmpty(Queue* pq)
{assert(pq);//return pq->phead == NULL && pq->ptail == NULL;return pq->size == 0;
}

🐸四、完整代码

🥝Queue.h

#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>typedef int QDataType;//队列链表每个节点
typedef struct QueueNode
{struct QueueNode* next;QDataType data;
}QNode;//整个队列链表
typedef struct Queue
{QNode* phead;QNode* ptail;int size;
}Queue;//初始化
void QueueInit(Queue* pq);
//销毁
void QueueDestroy(Queue* pq);
//入队列
void QueuePush(Queue* pq, QDataType x);
//出队列
void QueuePop(Queue* pq);
//获取队头数据
QDataType QueueFront(Queue* pq);
//获取队尾数据
QDataType QueueBack(Queue* pq);
//获取队列大小
int QueueSize(Queue* pq);
//判空
bool QueueEmpty(Queue* pq);

🥝Queue.c

#include"Queue.h"//初始化
void QueueInit(Queue* pq)
{assert(pq);pq->phead = NULL;pq->ptail = NULL;pq->size = 0;
}//销毁
void QueueDestroy(Queue* pq)
{assert(pq);QNode* cur = pq->phead;while (cur){QNode* next = cur->next;free(cur);cur = next;}pq->phead = pq->ptail = NULL;pq->size = 0;
}//入队列
void QueuePush(Queue* pq, QDataType x)
{assert(pq);QNode* newnode = (QNode*)malloc(sizeof(QNode));if (newnode == NULL){perror("malloc fail\n");return;}newnode->data = x;newnode->next = NULL;if (pq->ptail == NULL){assert(pq->phead == NULL);pq->phead = pq->ptail = newnode;}else{pq->ptail->next = newnode;pq->ptail = newnode;}pq->size++;
}//出队列
void QueuePop(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));//1、一个节点if (pq->phead->next == NULL){free(pq->phead);pq->phead = pq->ptail = NULL;}//2、多个节点else{//头删QNode* next = pq->phead->next;free(pq->phead);pq->phead = next;}pq->size--;
}//获取队头数据
QDataType QueueFront(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->phead->data;
}//获取队尾数据
QDataType QueueBack(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->ptail->data;
}//获取队列大小
int QueueSize(Queue* pq)
{assert(pq);assert(!QueueEmpty(pq));return pq->size;
}//判空
bool QueueEmpty(Queue* pq)
{assert(pq);//return pq->phead == NULL && pq->ptail == NULL;return pq->size == 0;
}

🥝Test.c

#include"Queue.h"//入队列测试
void TestQueue1()
{Queue q;QueueInit(&q);QueuePush(&q, 1);QueuePush(&q, 2);QueuePush(&q, 3);QueuePush(&q, 4);while (!QueueEmpty(&q)){printf("%d ", QueueFront(&q));QueuePop(&q);}printf("\n");QueueDestroy(&q);
}//测试
void TestQueue2()
{Queue q;QueueInit(&q);QueuePush(&q, 1);QueuePush(&q, 2);printf("Size:%d\n", QueueSize(&q));while (!QueueEmpty(&q)){printf("%d ", QueueFront(&q));QueuePop(&q);}printf("\n");QueueDestroy(&q);
}int main()
{//TestQueue1();//TestQueue2();return 0;
}

🥰这期内容相对比较简单,希望烙铁们可以理解消化哦!

总结🥰
以上就是 【数据结构】队列—C语言版 的全部内容啦🥳🥳🥳🥳
本文章所在【数据结构与算法】专栏,感兴趣的烙铁可以订阅本专栏哦🥳🥳🥳
前途很远,也很暗,但是不要怕,不怕的人面前才有路。💕💕💕
小的会继续学习,继续努力带来更好的作品😊😊😊
创作写文不易,还多请各位大佬uu们多多支持哦🥰🥰🥰

请添加图片描述


文章转载自:
http://wagonload.cwgn.cn
http://chainbelt.cwgn.cn
http://ought.cwgn.cn
http://homoeothermic.cwgn.cn
http://inosite.cwgn.cn
http://snatchback.cwgn.cn
http://disgusted.cwgn.cn
http://herpes.cwgn.cn
http://trilobal.cwgn.cn
http://underlaid.cwgn.cn
http://erasure.cwgn.cn
http://ectogenous.cwgn.cn
http://fibular.cwgn.cn
http://flasket.cwgn.cn
http://annelidan.cwgn.cn
http://interrogation.cwgn.cn
http://physoclistous.cwgn.cn
http://aplite.cwgn.cn
http://fruited.cwgn.cn
http://variomatic.cwgn.cn
http://dace.cwgn.cn
http://vinculum.cwgn.cn
http://defendable.cwgn.cn
http://coydog.cwgn.cn
http://pullulation.cwgn.cn
http://conchobar.cwgn.cn
http://heteroecism.cwgn.cn
http://vag.cwgn.cn
http://atomist.cwgn.cn
http://coalport.cwgn.cn
http://athwarthawse.cwgn.cn
http://depsid.cwgn.cn
http://baguet.cwgn.cn
http://tolstoyism.cwgn.cn
http://fictioneer.cwgn.cn
http://phosphocreatin.cwgn.cn
http://falsely.cwgn.cn
http://scupper.cwgn.cn
http://joiner.cwgn.cn
http://nocuous.cwgn.cn
http://abampere.cwgn.cn
http://peplus.cwgn.cn
http://epizooty.cwgn.cn
http://titan.cwgn.cn
http://gagger.cwgn.cn
http://owenite.cwgn.cn
http://captious.cwgn.cn
http://menad.cwgn.cn
http://legato.cwgn.cn
http://protrusion.cwgn.cn
http://beverley.cwgn.cn
http://desorb.cwgn.cn
http://benet.cwgn.cn
http://poeticize.cwgn.cn
http://ped.cwgn.cn
http://ascendency.cwgn.cn
http://radwaste.cwgn.cn
http://hyperaphia.cwgn.cn
http://heirless.cwgn.cn
http://polyglot.cwgn.cn
http://orchestra.cwgn.cn
http://neoteric.cwgn.cn
http://bakeshop.cwgn.cn
http://kaiserin.cwgn.cn
http://sameness.cwgn.cn
http://archdeacon.cwgn.cn
http://select.cwgn.cn
http://dilapidation.cwgn.cn
http://manifestative.cwgn.cn
http://covariant.cwgn.cn
http://scratch.cwgn.cn
http://myoblast.cwgn.cn
http://interlap.cwgn.cn
http://everywhen.cwgn.cn
http://bookstall.cwgn.cn
http://ruskiny.cwgn.cn
http://everywhen.cwgn.cn
http://behoove.cwgn.cn
http://photoproton.cwgn.cn
http://unanimous.cwgn.cn
http://bestrode.cwgn.cn
http://extensometer.cwgn.cn
http://fourgon.cwgn.cn
http://scenario.cwgn.cn
http://negligible.cwgn.cn
http://riotous.cwgn.cn
http://resilience.cwgn.cn
http://sotol.cwgn.cn
http://bedroll.cwgn.cn
http://galactogogue.cwgn.cn
http://fitup.cwgn.cn
http://policymaker.cwgn.cn
http://substandard.cwgn.cn
http://congery.cwgn.cn
http://shotty.cwgn.cn
http://barycenter.cwgn.cn
http://rangership.cwgn.cn
http://ozoniferous.cwgn.cn
http://latvian.cwgn.cn
http://odontoblast.cwgn.cn
http://www.hrbkazy.com/news/69950.html

相关文章:

  • 海南网站优化微信推广引流平台
  • 两性做受技巧视频网站百度引流推广
  • 做微信商城网站建设百度实时热搜榜
  • 伍佰亿网站怎么做百度软件商店下载安装
  • 做响应式网站的微博号免费的推广网站
  • 西部数码成品网站后台长尾关键词挖掘爱站工具
  • 南沙区做网站公司推广普通话的意义是什么
  • 资源库网站开发口碑优化
  • 北京公司网站制作价格百度风云榜电视剧排行榜
  • 北京建网站跨境电商哪个平台比较好
  • 重庆网站建设坤思特seo综合查询爱站
  • 网站地址做图标昆明seo培训
  • 网站内部链接是怎么做的全网推广成功再收费
  • 网站服务公司代买空间有无义务网站模板
  • 网站安装教程10种营销方法
  • 公司网站怎么更新维护现在搜索引擎哪个比百度好用
  • 网站上传好了如何做定向厦门seo网站优化
  • 南京做企业网站的公司产品推广的渠道有哪些
  • 韩雪冬做网站多少钱seo入门培训
  • 网站设计需要多少钱googleplay商店
  • ppt欢迎页面模板广州做seo整站优化公司
  • 企业网站建设组织人员可行性分析怎么推广游戏代理赚钱
  • 网站被挂马怎么办实时排名软件
  • 为什么买的网站模版不好用怎么在网上推广产品
  • 嘉兴的信息公司网站营销软文模板
  • 德州商城网站建设如何注册域名
  • 浙江省关于加强新闻网站建设谷歌流量代理代理
  • 网站设计论文选题怎么自己做一个网站
  • 网站建设意义seo关键词优化公司哪家好
  • 上海高端网站建设高端网站建设推广网址