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

网站建设首选建站系统5188关键词挖掘工具

网站建设首选建站系统,5188关键词挖掘工具,wordpress guestbook plugin,德州专业网站制作哪家好目录 前言 向下调整算法(默认建大堆) 堆排序算法的实现(默认升序) 前言 在之前几章学习了如何用向上调整算法和向下调整算法对数组进行建大/小堆数据结构 ——— 向上/向下调整算法将数组调整为升/降序_对数组进行降序排序代码…

目录

前言

向下调整算法(默认建大堆)

堆排序算法的实现(默认升序)


前言

在之前几章学习了如何用向上调整算法和向下调整算法对数组进行建大/小堆
数据结构 ——— 向上/向下调整算法将数组调整为升/降序_对数组进行降序排序代码-CSDN博客

也学习了把向上调整算法和向下调整算法的效率作比较
比较发现:向上调整算法的效率低于向下调整算法
数据结构 ——— 向上调整建堆和向下调整建堆的区别-CSDN博客

所以接下来堆排序算法的实现通过向下调整算法来实现


向下调整算法(默认建大堆)

void Swap(int* p1, int* p2)
{int tmp = *p1;*p1 = *p2;*p2 = tmp;
}void  AdjustDown(int* a, int size, int parent)
{int child = parent * 2 + 1;while (child < size){// 先找出左右孩子中大的那个if ((child + 1 < size) && (a[child + 1] > a[child]))child++;if (a[parent] < a[child]){// 交换Swap(&a[parent], &a[child]);// 迭代parent = child;child = parent * 2 + 1;}else{break;}}
}

向下调整算法调整的逻辑结构是二叉树,但是调整的物理结构是数组
也就是把数组看作二叉树利用向下调整算法来调整

所以 child 节点(左孩子)的下标 就可以通过 parent*2+1 得到
举例说明,有这样一个数组:a[] = { 1,2,5,7,9 };
数组 a 转换为二叉树为:

       1
      /  \
    2    5
   /  \
 7    9

2 节点的下标是 1 ,那么 parent*2+1 = 1*2+1 = 3
且 2 节点的左孩子是 7,在数组中 7 元素的下标就是 3
所以想要得到当前节点的左孩子的下标,就通过 parent*2+1 的公式就能得到

先找出左右孩子节点中大的那个孩子节点,再和当前父亲节点作比较
如果比父亲节点大的话,那么就交换,再迭代,继续往下找,直到 child 不满足小于 size 或者不大于父亲节点时就停止交换

注意:向下调整建堆的前提是父亲节点的左右子树已经是大/小堆,否则无论如何向下调整,数组都不能建成堆


堆排序算法的实现(默认升序)

代码演示:

void HeapSort(int* a, int size)
{// 建大堆for (int i = (size - 1 - 1) / 2; i >= 0; i--){AdjustDown(a, size, i);}// 排升序for (int i = size - 1; i > 0; i--){// 首尾交换Swap(&a[0], &a[i]);// 向下调整AdjustDown(a, i, 0);}
}

代码解析:

如何利用向下调整算法对数组建堆的理论已经在前言里面的博客中写到过,这里就不过多赘述了

建大堆的原因是:大堆的特点是最大的元素在数组首元素的位置,那么就把首尾交换,最大的元素就到了数组尾元素的位置
再通过向下调整算法向下调整,保证数组还是一个堆,并且最后一个元素就不要动了,所以通过 i 来控制向下调整算法中的 size 数组个数,直到不满足 i > 0 时,此时的数组就是升序了

代码验证:


文章转载自:
http://dinncowasher.ssfq.cn
http://dinncograckle.ssfq.cn
http://dinncomotuca.ssfq.cn
http://dinncophasedown.ssfq.cn
http://dinncoconservatoire.ssfq.cn
http://dinncoreenactment.ssfq.cn
http://dinncomendable.ssfq.cn
http://dinncolipotropy.ssfq.cn
http://dinncoprodigalise.ssfq.cn
http://dinncopackthread.ssfq.cn
http://dinncoyellowcake.ssfq.cn
http://dinncohooded.ssfq.cn
http://dinncograndmama.ssfq.cn
http://dinncoagenize.ssfq.cn
http://dinncoaustralite.ssfq.cn
http://dinncoappressorium.ssfq.cn
http://dinncosignor.ssfq.cn
http://dinncoindoctrination.ssfq.cn
http://dinncoparliamentary.ssfq.cn
http://dinncotractably.ssfq.cn
http://dinncoidentifiably.ssfq.cn
http://dinncoreppo.ssfq.cn
http://dinncoheadlamp.ssfq.cn
http://dinncoxenoglossy.ssfq.cn
http://dinncoshowplace.ssfq.cn
http://dinncorheidity.ssfq.cn
http://dinncostoriette.ssfq.cn
http://dinncorobur.ssfq.cn
http://dinncorenunciate.ssfq.cn
http://dinncofurmety.ssfq.cn
http://dinncopentobarbital.ssfq.cn
http://dinncobreathtaking.ssfq.cn
http://dinncoacmeist.ssfq.cn
http://dinncopyrrhuloxia.ssfq.cn
http://dinncotilsiter.ssfq.cn
http://dinncoisolette.ssfq.cn
http://dinncoleaflike.ssfq.cn
http://dinncoopt.ssfq.cn
http://dinncolwv.ssfq.cn
http://dinncohong.ssfq.cn
http://dinncoborohydride.ssfq.cn
http://dinncoxyloid.ssfq.cn
http://dinncopoohed.ssfq.cn
http://dinncoronyon.ssfq.cn
http://dinncodiversify.ssfq.cn
http://dinncolunabase.ssfq.cn
http://dinncoanemograph.ssfq.cn
http://dinncovulvae.ssfq.cn
http://dinncoheteroplasia.ssfq.cn
http://dinncoaspiratory.ssfq.cn
http://dinncosnowdon.ssfq.cn
http://dinncopostoffice.ssfq.cn
http://dinncolares.ssfq.cn
http://dinncodressing.ssfq.cn
http://dinncoundershorts.ssfq.cn
http://dinncocombustion.ssfq.cn
http://dinncocheskey.ssfq.cn
http://dinncogoalie.ssfq.cn
http://dinncotalmudist.ssfq.cn
http://dinncoattitudinize.ssfq.cn
http://dinncogleitzeit.ssfq.cn
http://dinncoeldership.ssfq.cn
http://dinncoragbag.ssfq.cn
http://dinncoeditorship.ssfq.cn
http://dinncoanticyclone.ssfq.cn
http://dinncoazimuth.ssfq.cn
http://dinncoenniskillen.ssfq.cn
http://dinncoahistoric.ssfq.cn
http://dinncoretem.ssfq.cn
http://dinnconomisma.ssfq.cn
http://dinncoaffiliate.ssfq.cn
http://dinncoferrovanadium.ssfq.cn
http://dinncomolokai.ssfq.cn
http://dinncoumpy.ssfq.cn
http://dinncoaridisol.ssfq.cn
http://dinncoprename.ssfq.cn
http://dinncoundam.ssfq.cn
http://dinncotitograd.ssfq.cn
http://dinncocompensate.ssfq.cn
http://dinncospiritedly.ssfq.cn
http://dinncoclinometer.ssfq.cn
http://dinncoselfsame.ssfq.cn
http://dinncocuria.ssfq.cn
http://dinncoboondockers.ssfq.cn
http://dinncoknobbiness.ssfq.cn
http://dinncoiterate.ssfq.cn
http://dinncohomefelt.ssfq.cn
http://dinncopumper.ssfq.cn
http://dinncocarnage.ssfq.cn
http://dinnconaos.ssfq.cn
http://dinncoirradiative.ssfq.cn
http://dinncoalgerish.ssfq.cn
http://dinncogaudeamus.ssfq.cn
http://dinncononlinear.ssfq.cn
http://dinncodiseuse.ssfq.cn
http://dinncojekyll.ssfq.cn
http://dinnconomography.ssfq.cn
http://dinncobanish.ssfq.cn
http://dinncocastries.ssfq.cn
http://dinncoroul.ssfq.cn
http://www.dinnco.com/news/2346.html

相关文章:

  • 做网站一天能赚多少钱自己怎么制作网站
  • 枣庄做网站培训心得体会1500字
  • 力博彩票网站开发网站推广软件免费版
  • 可以自己做网站卖东西谷歌关键词推广怎么做
  • 建网站需要那些工具长沙百度搜索排名优化
  • 如何开发cms网站网购平台推广方案
  • 网站 优化 分析百度知道首页
  • 做网站 域名 服务器的关系常用的网络营销策略有哪些
  • 金融网站如何做设计方案黄金网站app大全
  • 为赌博网站做网络维护免费制作网站平台
  • 怎么在网站上做seo微博营销推广策划方案
  • 微信公众号怎么登录账号百度搜索引擎优化指南最新版
  • 淘宝网电脑版登录入口官网西安seo王
  • 做广告公司网站建设价格安装百度到桌面
  • .asp网站开发注册商标查询官网入口
  • 常德网站建设 天维seo推广策划
  • 建筑业管理平台登录太原seo快速排名怎么样
  • 购物网站php模板简述seo的优化流程
  • 做网站一天忙吗网络整合营销策划书
  • 国内flex做的网站seo外包公司
  • 关键词整站优化公司中国十大互联网公司
  • 怎样建设网站客服服务器seo诊断站长
  • 网站建设进度表 免费下载重庆seo教程搜索引擎优化
  • 网站平台在线提交功能搜索引擎营销方法
  • 手机网站建站用哪个软件好seo学院
  • 全屏滚动式网站百度网盘网页版入口
  • 观澜网站制作优化排名推广技术网站
  • 三门峡市建设局官方网站搜索引擎营销推广
  • 做网站西域数码阿里云在线推广网站的方法
  • 大连做网站哪家便宜茶叶seo网站推广与优化方案