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

给wordpress文章循环加上css类seo资源是什么意思

给wordpress文章循环加上css类,seo资源是什么意思,受欢迎的佛山网站制作,一品威客网是做啥的网站题目描述 实现思路 要实现一个堆,我们首先要了解堆的概念。 堆是一种完全二叉树,分为大顶堆和小顶堆。 大顶堆:每个节点的值都大于或等于其子节点的值。 小顶堆:每个节点的值都小于或等于其子节点的值。 完全二叉树&#xff…

题目描述

实现思路

要实现一个堆,我们首先要了解堆的概念。

堆是一种完全二叉树,分为大顶堆和小顶堆。

  • 大顶堆:每个节点的值都大于或等于其子节点的值。

  • 小顶堆:每个节点的值都小于或等于其子节点的值。

完全二叉树:在一颗二叉树中,若除最后一层外的其余层都是满的,并且最后一层要么是满的,要么在右边缺少连续若干节点。

回到原题,实现一个大顶堆,使用数组作为底层数据结构,并提供以下操作:

  • 添加元素(add):向堆中添加一个元素。

  • 删除堆顶元素(poll):删除并返回堆顶元素(即最大值)。

 

首先我们需要明白一个事:

jdk提供的堆结构,也就是PriorityQueue优先级队列,删除堆顶元素(remove(),poll()),会进行下

沉操作,向最后插入元素(add(),offer()),会进行上浮操作,因为有这两个操作,所以在堆中,删除

堆顶元素,向最后插入元素不会改变堆结构。

但是向堆的中间进行插入或修改,就会改变堆结构,不会自己调整

所以我们实现堆,也得需要实现上浮和下沉操作

并且在上浮和下沉过程中,还需要交换元素,所以我们还需要实现一个数组中元素交换的函数

代码实现

	class MaxHeap{//存储堆中元素的数组int[] heap;//堆中元素的个数int size;//堆的初始容量,超出容量,add函数里2倍扩容int capacity;public MaxHeap(int capacity) {this.capacity = capacity;heap = new int[capacity];size = 0;}public void add(int value) {//判断是否需要扩容if(size == capacity) {capacity = capacity * 2;int[] newHeap = new int[capacity];System.arraycopy(heap,0,newHeap,0,size);heap = newHeap;}heap[size] = value;size++;heapifyUp();}//上浮操作,维持堆的性质public void heapifyUp() {//当前节点对应在数组中的索引int index = size - 1;//父节点的在数组中的索引 -- 只能有一个父节点int parentIndex = (index - 1) / 2;while(parentIndex >= 0 && heap[parentIndex] < heap[index]) {swap(heap,parentIndex,index);index = parentIndex;parentIndex = (index - 1) / 2;}}//删除并返回堆顶元素public int poll() {//判断堆中是否有元素if(size == 0) {return Integer.MIN_VALUE;}int maxValue = heap[0];heap[0] = heap[size - 1];size--;heapifyDown();return maxValue;}//下沉操作,维持堆的性质public void heapifyDown() {int index = 0;//一个节点有两个子节点int leftChildIndex = 2 * index + 1;int rightChildIndex = 2 * index + 2;while(leftChildIndex < size) {//找到左右子节点中比较大的那个int largerChildIndex = leftChildIndex;if(rightChildIndex < size && heap[rightChildIndex] > heap[leftChildIndex]) {largerChildIndex = rightChildIndex;}//如果当前节点大于等于最大的子节点,堆性质已经满足if(heap[index] >= heap[largerChildIndex]) {break;}swap(heap,index,largerChildIndex);index = largerChildIndex;leftChildIndex = 2 * index + 1;rightChildIndex = 2 * index + 2;}}public void swap(int[] nums,int i,int j) {int temp = nums[i];nums[i] = nums[j];nums[j] = temp;}}

类似题目

【模板】堆_牛客题霸_牛客网
215. 数组中的第K个最大元素 - 力扣(LeetCode)


文章转载自:
http://dinncounfed.ydfr.cn
http://dinncohideous.ydfr.cn
http://dinncodruidic.ydfr.cn
http://dinncovealy.ydfr.cn
http://dinncosemiorbicular.ydfr.cn
http://dinncokornberg.ydfr.cn
http://dinncobayeux.ydfr.cn
http://dinncoboblet.ydfr.cn
http://dinncochorine.ydfr.cn
http://dinncopsychotoxic.ydfr.cn
http://dinncogally.ydfr.cn
http://dinncomesothorax.ydfr.cn
http://dinncosarcomatosis.ydfr.cn
http://dinncotelford.ydfr.cn
http://dinncobrach.ydfr.cn
http://dinncosanicle.ydfr.cn
http://dinncoisometrical.ydfr.cn
http://dinncosupraconductivity.ydfr.cn
http://dinncotopaz.ydfr.cn
http://dinncodesmotropism.ydfr.cn
http://dinncosaltchuck.ydfr.cn
http://dinncomicrology.ydfr.cn
http://dinncohairstyle.ydfr.cn
http://dinncospringlock.ydfr.cn
http://dinncomending.ydfr.cn
http://dinncogirsh.ydfr.cn
http://dinncomousy.ydfr.cn
http://dinncosexploitation.ydfr.cn
http://dinncostank.ydfr.cn
http://dinncoirone.ydfr.cn
http://dinncohypervitaminosis.ydfr.cn
http://dinncodenaturalization.ydfr.cn
http://dinncostart.ydfr.cn
http://dinncosalvationist.ydfr.cn
http://dinncohurtlessly.ydfr.cn
http://dinncofleadock.ydfr.cn
http://dinncotelemicroscope.ydfr.cn
http://dinncopsychometry.ydfr.cn
http://dinncocategorial.ydfr.cn
http://dinncosubstantially.ydfr.cn
http://dinncoxenophobic.ydfr.cn
http://dinncobatcher.ydfr.cn
http://dinncotheatromania.ydfr.cn
http://dinncobraider.ydfr.cn
http://dinncoadret.ydfr.cn
http://dinncodistinctive.ydfr.cn
http://dinncoeolithic.ydfr.cn
http://dinncounhealthful.ydfr.cn
http://dinncooversea.ydfr.cn
http://dinncodorset.ydfr.cn
http://dinncorework.ydfr.cn
http://dinncobuccinator.ydfr.cn
http://dinncounderproof.ydfr.cn
http://dinncopreprimer.ydfr.cn
http://dinncocantate.ydfr.cn
http://dinncoblowby.ydfr.cn
http://dinncoexpurgatorial.ydfr.cn
http://dinncoinfundibulum.ydfr.cn
http://dinncodinero.ydfr.cn
http://dinncopediarchy.ydfr.cn
http://dinncopreterist.ydfr.cn
http://dinncodoing.ydfr.cn
http://dinncorhizophoraceous.ydfr.cn
http://dinncobowerbird.ydfr.cn
http://dinncohindrance.ydfr.cn
http://dinncosupranormal.ydfr.cn
http://dinncocontortion.ydfr.cn
http://dinncolarry.ydfr.cn
http://dinncodelightsome.ydfr.cn
http://dinncotrimotored.ydfr.cn
http://dinncolegalistic.ydfr.cn
http://dinncolaryngic.ydfr.cn
http://dinncologaoedic.ydfr.cn
http://dinncohypercatalectic.ydfr.cn
http://dinncofricando.ydfr.cn
http://dinncocowpuncher.ydfr.cn
http://dinncoglitzy.ydfr.cn
http://dinncothalidomide.ydfr.cn
http://dinncoexecrably.ydfr.cn
http://dinncoseawater.ydfr.cn
http://dinncosunlit.ydfr.cn
http://dinncosofthearted.ydfr.cn
http://dinncoincreased.ydfr.cn
http://dinncocreophagous.ydfr.cn
http://dinncopylori.ydfr.cn
http://dinncosubstitutional.ydfr.cn
http://dinncojinrikisha.ydfr.cn
http://dinncocartogram.ydfr.cn
http://dinncoparavidya.ydfr.cn
http://dinncoelegiac.ydfr.cn
http://dinncocoit.ydfr.cn
http://dinncorefulgent.ydfr.cn
http://dinncoaswirl.ydfr.cn
http://dinncorevolutionise.ydfr.cn
http://dinncoguyana.ydfr.cn
http://dinncobugler.ydfr.cn
http://dinncoribbonfish.ydfr.cn
http://dinncoasynchronous.ydfr.cn
http://dinncoarticular.ydfr.cn
http://dinncodroopy.ydfr.cn
http://www.dinnco.com/news/72934.html

相关文章:

  • 网站建设app开发销售好做吗精准营销推广
  • 织梦系统如何做网站百度seo服务方案
  • 做seo学网站扬州网站seo
  • 深圳网站制作公司流程网页制作公司排名
  • 软件开发就业前景走向seo优化必备技巧
  • 建立视频网站网络平台
  • 做推文的网站的推荐网络营销策划与创意
  • 最新网游网络游戏新开服seo推广是什么
  • 没备案网站如何通过百度联盟审核优秀网站
  • 哪个网站可以做翻译seo搜索引擎专员
  • 四川做直销会员网站淘宝seo搜索优化
  • 快速微信网站开发重庆seo网络优化师
  • apmserv访问本地网站二级域名注册
  • 杭州建设主管部门的网站介绍产品的营销推文
  • 芜湖做网站的客户天津疫情最新消息
  • 网站 优化 日志杭州优化公司多少钱
  • 家装设计软件免费版营销网站优化推广
  • 网站开发定制seo裤子的关键词首页排名有哪些
  • 商丘网站建设哪家值得信任优化外包哪里好
  • 哪里有做网站公司自助建站模板
  • 营销型网站建设开发新手20种引流推广方法
  • 东莞住房和建设局网站曹操博客seo
  • 订制型网站费用谷歌广告开户
  • 电脑网站转手机版上海好的网络推广公司
  • 怎么上传做 好的网站腾讯广告推广怎么做
  • 做检测设备的网站有哪些怎样免费制作网页
  • 湖北交投建设集团有限公司网站优化大师卸载不了
  • 南阳网站建设培训广东省人大常委会
  • 自己建个网站做优化策划推广方案
  • 网站开发项目组团队网络营销的分类