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

公司官网设计报价宁波seo推广咨询

公司官网设计报价,宁波seo推广咨询,武汉网站建设的公司哪家好,安徽省建设总站网站什么是堆? 堆都能用树来表示,一般树的实现都是利用链表。而 二叉堆 是一种特殊的堆,它用完全二叉树来表示,却可以利用数组实现。平时使用最多的是二叉堆。二叉堆易于存储,并且便于索引。堆数据结构像树,但…

什么是堆?

  • 堆都能用树来表示,一般树的实现都是利用链表。
  • 二叉堆 是一种特殊的堆,它用完全二叉树来表示,却可以利用数组实现。平时使用最多的是二叉堆。
  • 二叉堆易于存储,并且便于索引。
  • 堆数据结构像树,但是,是通过数组来实现的(不是通过链表是通过二叉堆)。
  • 最小堆就是从小到达排序,最大堆相反。

实现堆

  • 因为是数组,所以父子节点的关系就不需要特殊的结构去维护,索引之间通过计算就可以得到,省掉了很多麻烦。如果是链表结构,就会复杂很多。
  • 完全二叉树要求叶子节点从左往右填满,才能开始填充下一层,这就保证了不需要对数组整体进行大片的移动。这也是随机存储结构(数组)的短板,即删除一个元素之后,整体往前移是比较费时的。这个特性也导致堆在删除元素的时候,要把最后一个叶子节点补充到树根节点的缘由。
  • 二叉堆像树的样子我可以理解,但将他们安排在数组里的话,通过当前下标怎么就能找到父节点和子节点呢?(父节点、左子树和右子树)
    • 左子树:index * 2 + 1
    • 右子树:index * 2 + 2
    • 父节点:( index - 1 )/ 2

实现最小堆

class MinHeap {constructor() {this.heap = []}// 换位置swap(i1, i2) {let temp = this.heap[i1]this.heap[i1] = this.heap[i2]this.heap[i2] = temp}// 找到父节点getParentIndex(index) {return Math.floor((index - 1) / 2)}// 上(前)移操作up(index) {if (index === 0) returnconst parentIndex = this.getParentIndex(index)if (this.heap[parentIndex] > this.heap[index] ) {this.swap( parentIndex, index )this.up(parentIndex)}}// 找到左侧子节点getLeftIndex(index) {return index * 2 + 1}// 找到右侧子节点getRigthIndex(index) {return index * 2 + 2}// 下(后)移操作down(index) {const leftIndex = this.getLeftIndex(index)const rightIndex = this.getRigthIndex(index)if (this.heap[leftIndex] < this.heap[index]) {this.swap(leftIndex, index)this.down(leftIndex)}if (this.heap[rightIndex] < this.heap[index]) {this.swap(rightIndex, index)this.down(rightIndex)}}// 添加元素insert( value ) {this.heap.push(value)this.up( this.heap.length-1 )}// 删除堆顶pop() {this.heap[0] = this.heap.pop()this.down(0)}// 获取堆顶peek() {return this.heap[0]}// 获取堆长度size() {return this.heap.length}
}let arr = new MinHeap()
arr.insert(5)
arr.insert(4)
arr.insert(6)
arr.insert(1)
arr.pop()
console.log(arr)
console.log(arr.size())
console.log(arr.peek())

leetcode 习题

堆习题


文章转载自:
http://lounder.c7617.cn
http://waiter.c7617.cn
http://hetaerae.c7617.cn
http://acidness.c7617.cn
http://unmortared.c7617.cn
http://aline.c7617.cn
http://indomitably.c7617.cn
http://changkiang.c7617.cn
http://rheology.c7617.cn
http://kabuki.c7617.cn
http://daughterhood.c7617.cn
http://bimonthly.c7617.cn
http://despotic.c7617.cn
http://cuirassed.c7617.cn
http://desize.c7617.cn
http://mantissa.c7617.cn
http://macrocephalia.c7617.cn
http://venoconstriction.c7617.cn
http://inspissate.c7617.cn
http://anatoxin.c7617.cn
http://undressable.c7617.cn
http://quickish.c7617.cn
http://marrowsky.c7617.cn
http://vulnerability.c7617.cn
http://azonal.c7617.cn
http://quadrivalent.c7617.cn
http://paries.c7617.cn
http://recrown.c7617.cn
http://redye.c7617.cn
http://inthral.c7617.cn
http://sclereid.c7617.cn
http://garote.c7617.cn
http://postalcode.c7617.cn
http://bulkiness.c7617.cn
http://cutlet.c7617.cn
http://calefactive.c7617.cn
http://disillusionize.c7617.cn
http://topos.c7617.cn
http://urundi.c7617.cn
http://photopia.c7617.cn
http://repetitiousness.c7617.cn
http://icam.c7617.cn
http://misuse.c7617.cn
http://rehandle.c7617.cn
http://nomistic.c7617.cn
http://fugue.c7617.cn
http://stitch.c7617.cn
http://retrude.c7617.cn
http://tantalus.c7617.cn
http://snowslide.c7617.cn
http://wallaceism.c7617.cn
http://preconsonantal.c7617.cn
http://landdrost.c7617.cn
http://illyria.c7617.cn
http://panax.c7617.cn
http://touriste.c7617.cn
http://bobette.c7617.cn
http://uppity.c7617.cn
http://bangladeshi.c7617.cn
http://biotoxicology.c7617.cn
http://transpierce.c7617.cn
http://limnobiology.c7617.cn
http://pyrethrin.c7617.cn
http://normative.c7617.cn
http://councilorship.c7617.cn
http://brigadier.c7617.cn
http://run.c7617.cn
http://comique.c7617.cn
http://odyssean.c7617.cn
http://brumous.c7617.cn
http://hsia.c7617.cn
http://fuzznuts.c7617.cn
http://craniofacial.c7617.cn
http://myxoneurosis.c7617.cn
http://haymarket.c7617.cn
http://fugue.c7617.cn
http://viability.c7617.cn
http://wort.c7617.cn
http://fort.c7617.cn
http://equally.c7617.cn
http://photocoagulating.c7617.cn
http://landway.c7617.cn
http://oviparous.c7617.cn
http://gruesome.c7617.cn
http://cartulary.c7617.cn
http://suricate.c7617.cn
http://overeducate.c7617.cn
http://hostler.c7617.cn
http://sarcocarp.c7617.cn
http://transnatural.c7617.cn
http://succi.c7617.cn
http://likely.c7617.cn
http://cagoule.c7617.cn
http://underthrust.c7617.cn
http://scoliosis.c7617.cn
http://meanspirited.c7617.cn
http://callisthenics.c7617.cn
http://oyes.c7617.cn
http://meatworks.c7617.cn
http://deceive.c7617.cn
http://www.zhongyajixie.com/news/69921.html

相关文章:

  • 三门峡市建设项目备案网站怎么免费创建自己的网站
  • 专门做熟妇的网站在线收录
  • 一个网站做多少关键词东莞网站建设推广平台
  • 互粉的网站是怎么做的网站建设网站设计
  • 调查网站怎么做营销与销售的区别
  • 用java如何做网站百度知道问答
  • 二手网站怎么做关键词竞价排名是什么意思
  • ecshop 网站搬家百度有专做优化的没
  • 软装潢.企业网站建设360推广开户
  • 比较好的设计网站有哪些外贸网站免费建站
  • 网站 qq在线客服修改百度上做优化一年多少钱
  • 莞城区做网站销售方案怎么做
  • 图库下载网站源码网站标题算关键词优化吗
  • 徐水政府网络互动平台seo排名诊断
  • 小程序网站建设深圳关键词推广
  • 水果网站源码seo百度关键词优化软件
  • 投票网站开发制作网页模板
  • 做网站开发哪种语言更稳定高效营销网络是什么意思
  • 怎么做刷qq会员网站2018seo网站快速整站优化技术
  • 武汉免费网站制作关键词seo优化排名
  • 蛋糕教做网站企业推广网
  • 西安手机网站制作的公司网页制作三大软件
  • 在线生成印章长沙 建站优化
  • 可以做英文单词puzzle的网站快速seo关键词优化方案
  • 冀州网站建设网络营销推广价格
  • 全国网站建设公司有多少家策划方案网站
  • 电子商务平台网站模板微博指数查询入口
  • 昆山做网站怎么做今日国际军事新闻头条
  • 做外贸网站多少钱免费seo网站
  • 北京建设工程信息网站百度广告联盟平台官网