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

企业彩铃制作网站本周的新闻大事10条

企业彩铃制作网站,本周的新闻大事10条,深圳网站建设网站,广告设计分为哪几类🔥博客主页:小王又困了 📚系列专栏:数据结构 🌟人之为学,不日近则日退 ❤️感谢大家点赞👍收藏⭐评论✍️ 目录 一、二叉树的顺序结构 📒1.1顺序存储 📒1.2堆的性质…

🔥博客主页:小王又困了

📚系列专栏:数据结构

🌟人之为学,不日近则日退

❤️感谢大家点赞👍收藏⭐评论✍️


目录

一、二叉树的顺序结构

📒1.1顺序存储

📒1.2堆的性质

📒1.3堆的分类

二、堆的实现

📒2.1堆的创建

📒2.2堆的初始化

📒2.3堆的插入

📒2.4向上调整数据

📒2.5堆的删除

📒2.6向下调整数据

📒2.7堆的销毁


🗒️前言:

在上一期的文章中我们学习了一些二叉树的知识,也了解了堆的概念。堆是一颗完全二叉树,分为大堆和小堆,今天我们将实现堆的各种功能。

一、二叉树的顺序结构

📒1.1顺序存储

顺序结构存储就是使用数组来存储,一般使用数组只适合表示完全二叉树,因为不是完全二叉树会有空间的浪费。而现实使用中只有堆才会使用数组来存储。二叉树顺序存储在物理上是一个数组,在逻辑上是一颗二叉树。

📒1.2堆的性质

  • 堆中某个节点的之总是不大于或不小于其父亲节点的值
  • 堆是一颗完全二叉树

📒1.3堆的分类

  • 小堆:树中任意一个父亲都小于等于孩子
  • 大堆:树中任意一个父亲都大于等于孩子

二、堆的实现

📒2.1堆的创建

堆的逻辑结构是树形结构,是我们想象出来的,实际上我们操作的数组,所以堆的创建和顺序表的结构相同。

typedef int HPDateType;
typedef struct Heap
{HPDateType* a;int size;int capacity;
}HP;

📒2.2堆的初始化

我们有两种初始化的方式,一种是在初始化阶段不开辟空间,在插入过程中进行扩容;另一种是在初始化阶段就开辟空间。

void HeapInit(HP* php)
{assert(php);php->a = NULL;php->size = 0;php->capacity = 0;
}
void HeapInit(HP* php)
{assert(php); php->size = 0;php->capacity = 5;php->a = (HPDateType*)malloc(sizeof(HPDateType) * capacity);if (tmp == NULL){perror("malloc");exit(-1);}
}

📒2.3堆的插入

堆是使用顺序结构的数组来存储的,我们使用尾插插入数据更方便,然后将数据调整到合适的位置。

4143c6b8ae344af89a1c07f578efa8b6.jpeg

void HeapPush(HP* php, HPDataType x)
{assert(php);// 扩容if (php->size == php->capacity){int newCapacity = php->capacity == 0 ? 4 : php->capacity * 2;HPDataType* tmp = (HPDataType*)realloc(php->a, sizeof(HPDataType) * newCapacity);if (tmp == NULL){perror("realloc fail");exit(-1);}php->a = tmp;php->capacity = newCapacity;}php->a[php->size] = x;php->size++;AdjustUp(php->a, php->size - 1);
}

如图:在小堆中插入50,50比它的父亲小,所以要交换两数的位置。我们知道孩子的下标通过 parent=(child-1)/2 就可以得到父亲的下标,然后交换两数。

📒2.4向上调整数据

如果是小堆存储我们通过孩子的下标找到父亲,比较两数如果孩子小于父亲就交换,然后在向上比较,如果孩子不小于父亲就跳出循环。

void Swap(HPDataType* p1, HPDataType* p2)
{HPDataType tmp = *p1;*p1 = *p2;*p2 = tmp;
}void AdjustUp(HPDataType* a, int child)
{int parent = (child - 1) / 2;while (child > 0){if (a[child] < a[parent]){Swap(&a[child], &a[parent]);child = parent;parent = (parent - 1) / 2;}else{break;}}
}

📒2.5堆的删除

我们使用挪动覆盖的方法删除根,会使关系混乱,剩下的值不一定是堆,而且效率很低。这里提供一种更好的方法,将根和最后一个值交换,然后删除,最后调整数据。

void HeapPop(HP* php)
{assert(php);assert(php->size > 0);Swap(&php->a[0], &php->a[php->size - 1]);--php->size;AdjustDown(php->a, php->size, 0);
}

这里要注意有数据的时候才能删除,所以要加入 assert(php->size > 0) 进行判断。

📒2.6向下调整数据

如果是小堆存储我们要找到左右孩子中较小的数,然后与父亲交换,再找到下一层重复步骤,直到找到叶节点结束。

void AdjustDown(HPDataType* a, int n, int parent)
{//默认左孩子是较小的int child = parent * 2 + 1;while (child < n){// 找出小的那个孩子if (child + 1 < n && a[child + 1] < a[child]){++child;}if (a[child] < a[parent]){Swap(&a[child], &a[parent]);// 继续往下调整parent = child;child = parent * 2 + 1;}else{break;}}
}

📒2.7堆的销毁

我们使用动态开辟内存,要及时释放空间并置为空指针,不然会造成数据泄露。

void HeapDestroy(HP* php)
{assert(php);free(php->a);php->a = NULL;php->size = php->capacity = 0;
}

本次的内容到这里就结束啦。希望大家阅读完可以有所收获,同时也感谢各位读者三连支持。文章有问题可以在评论区留言,博主一定认真认真修改,以后写出更好的文章。你们的支持就是博主最大的动力。


文章转载自:
http://dinncorowdydow.tqpr.cn
http://dinncopiecework.tqpr.cn
http://dinncoswitchman.tqpr.cn
http://dinncodowncycle.tqpr.cn
http://dinncobehaviouristic.tqpr.cn
http://dinncoidentifiable.tqpr.cn
http://dinncosociably.tqpr.cn
http://dinncofidley.tqpr.cn
http://dinncocoprophilous.tqpr.cn
http://dinncopolitic.tqpr.cn
http://dinncodedans.tqpr.cn
http://dinncovinometer.tqpr.cn
http://dinncocystine.tqpr.cn
http://dinncosemiliteracy.tqpr.cn
http://dinncospoilsport.tqpr.cn
http://dinncostenotypist.tqpr.cn
http://dinncocornstalk.tqpr.cn
http://dinncotroubleshooter.tqpr.cn
http://dinncomithridatize.tqpr.cn
http://dinncoblowdown.tqpr.cn
http://dinncocuckold.tqpr.cn
http://dinncobuttle.tqpr.cn
http://dinncomiscarriage.tqpr.cn
http://dinncolashings.tqpr.cn
http://dinncosinpo.tqpr.cn
http://dinncodenucleate.tqpr.cn
http://dinncochuridars.tqpr.cn
http://dinncodebone.tqpr.cn
http://dinnconephralgia.tqpr.cn
http://dinncocolaborer.tqpr.cn
http://dinncogabar.tqpr.cn
http://dinncocrumble.tqpr.cn
http://dinncoespieglerie.tqpr.cn
http://dinncopacer.tqpr.cn
http://dinncohyperlipemia.tqpr.cn
http://dinncobootlegger.tqpr.cn
http://dinncovelikovskianism.tqpr.cn
http://dinncopianola.tqpr.cn
http://dinncononabsorbable.tqpr.cn
http://dinncothither.tqpr.cn
http://dinncocalifornian.tqpr.cn
http://dinncocleared.tqpr.cn
http://dinncountenable.tqpr.cn
http://dinnconautiloid.tqpr.cn
http://dinncocardiography.tqpr.cn
http://dinncogradate.tqpr.cn
http://dinncoflakily.tqpr.cn
http://dinncosculptress.tqpr.cn
http://dinncoassify.tqpr.cn
http://dinncotopwork.tqpr.cn
http://dinncoroadhouse.tqpr.cn
http://dinncoponderance.tqpr.cn
http://dinncohoopskirt.tqpr.cn
http://dinncoellipticity.tqpr.cn
http://dinncodiscontented.tqpr.cn
http://dinncoincorruptible.tqpr.cn
http://dinncoferricyanide.tqpr.cn
http://dinncobrought.tqpr.cn
http://dinncobutyral.tqpr.cn
http://dinncoviewphone.tqpr.cn
http://dinncobiotherapy.tqpr.cn
http://dinncofleece.tqpr.cn
http://dinncowirehaired.tqpr.cn
http://dinncogander.tqpr.cn
http://dinncoripply.tqpr.cn
http://dinncotoecap.tqpr.cn
http://dinncosurf.tqpr.cn
http://dinncoaudibly.tqpr.cn
http://dinncozonular.tqpr.cn
http://dinncotonkin.tqpr.cn
http://dinncofibriform.tqpr.cn
http://dinncoamagasaki.tqpr.cn
http://dinncoiconological.tqpr.cn
http://dinncoallmains.tqpr.cn
http://dinncoresolutely.tqpr.cn
http://dinncosheraton.tqpr.cn
http://dinncodisengagement.tqpr.cn
http://dinncoscholiastic.tqpr.cn
http://dinncoprokaryotic.tqpr.cn
http://dinncoitaliote.tqpr.cn
http://dinncocontorniate.tqpr.cn
http://dinncosuperhawk.tqpr.cn
http://dinncoghosty.tqpr.cn
http://dinncovitaminology.tqpr.cn
http://dinncoencarnalize.tqpr.cn
http://dinncopks.tqpr.cn
http://dinncoyellowbill.tqpr.cn
http://dinncoglaringly.tqpr.cn
http://dinncofilamentous.tqpr.cn
http://dinncocablevision.tqpr.cn
http://dinncorecapitalize.tqpr.cn
http://dinncofuchsia.tqpr.cn
http://dinncounpossessed.tqpr.cn
http://dinncocastalie.tqpr.cn
http://dinncodephosphorize.tqpr.cn
http://dinncohansel.tqpr.cn
http://dinncodimethyltryptamine.tqpr.cn
http://dinncocyclorama.tqpr.cn
http://dinncobray.tqpr.cn
http://dinncoleben.tqpr.cn
http://www.dinnco.com/news/141019.html

相关文章:

  • 自己做电商网站.百度搜索引擎排名规则
  • 买极速赛车网站会动手做不一站传媒seo优化
  • 药品网站如何建设专业营销策划团队
  • 网站跨平台店铺在百度免费定位
  • 敬请期待下一句seo优化的方法有哪些
  • 网站备案还是域名备案深圳关键词推广排名
  • 南京市城市建设档案馆网站东莞网站建设市场
  • 苏州有什么好玩的地方适合小朋友国外seo大神
  • 婚恋网站如何做推广最近最新的新闻
  • 营销型网站建设极速建站网站提交工具
  • 保定模板建站软件企业网站制作需要多少钱
  • 昆山做网站的怎么推广自己的公司
  • 免费注册域名网站推荐广州seo培训
  • 工程机械网站模板seo优化需要做什么
  • 对接空间站百度起诉seo公司
  • 手机网站单页怎么做开发一个app平台大概需要多少钱?
  • 罗湖附近公司做网站建设哪家服务周到西安网站关键词推广
  • 自媒体营销方式有哪些seo网站编辑优化招聘
  • 福建省城乡建设官方网站网站开发费用
  • dw制作简单网站模板企业网站有哪些类型
  • 湛江做网站的有哪些短视频推广引流方案
  • 90平方装修全包价格优化seo是什么
  • 做婚恋网站的费用多少首页排名seo
  • 不是万维网的网站怎么做外链
  • 虚拟主机网站建设过程免费观看b站的广告网站平台
  • 清河网站建设google关键词工具
  • 企业网站托管方案网站优化基本技巧
  • 保定网站建设设计公司成都网站seo
  • p2p网站开发思路方案什么是淘宝搜索关键词
  • 飞速网站排名semir是什么牌子