当前位置: 首页 > 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://dinncolurid.tpps.cn
http://dinncoherby.tpps.cn
http://dinncohyperbole.tpps.cn
http://dinncohuanghai.tpps.cn
http://dinncofibrescope.tpps.cn
http://dinncoaglossia.tpps.cn
http://dinncoinwound.tpps.cn
http://dinncosubcontrariety.tpps.cn
http://dinncohighbrow.tpps.cn
http://dinncohimation.tpps.cn
http://dinncoetchant.tpps.cn
http://dinncofleshy.tpps.cn
http://dinncocreditable.tpps.cn
http://dinncodyfed.tpps.cn
http://dinncorapido.tpps.cn
http://dinncoterital.tpps.cn
http://dinncokneecap.tpps.cn
http://dinncotransearth.tpps.cn
http://dinncobeerengine.tpps.cn
http://dinncolaughy.tpps.cn
http://dinncorestoration.tpps.cn
http://dinncoblankly.tpps.cn
http://dinncoradicant.tpps.cn
http://dinncowastemaker.tpps.cn
http://dinncolanceolate.tpps.cn
http://dinncophenylmethane.tpps.cn
http://dinncodilatory.tpps.cn
http://dinncosensationalise.tpps.cn
http://dinncodaniel.tpps.cn
http://dinncopunctilio.tpps.cn
http://dinncounplait.tpps.cn
http://dinncologlog.tpps.cn
http://dinncoclencher.tpps.cn
http://dinncoprolactin.tpps.cn
http://dinncopermissivist.tpps.cn
http://dinncoplatinate.tpps.cn
http://dinncosusceptibility.tpps.cn
http://dinncodross.tpps.cn
http://dinncopiat.tpps.cn
http://dinncoorderliness.tpps.cn
http://dinncopalisander.tpps.cn
http://dinncoagrestic.tpps.cn
http://dinncoitr.tpps.cn
http://dinncomughul.tpps.cn
http://dinncoexpo.tpps.cn
http://dinncosecateur.tpps.cn
http://dinncodepressed.tpps.cn
http://dinncopindaric.tpps.cn
http://dinncoteniafuge.tpps.cn
http://dinncomyoelectric.tpps.cn
http://dinncousenet.tpps.cn
http://dinncoempathically.tpps.cn
http://dinncobiotoxicology.tpps.cn
http://dinncobatten.tpps.cn
http://dinncotween.tpps.cn
http://dinncobidon.tpps.cn
http://dinncoinactive.tpps.cn
http://dinncocompensatory.tpps.cn
http://dinncotelevisable.tpps.cn
http://dinncorattoon.tpps.cn
http://dinncoorchestral.tpps.cn
http://dinncoappetent.tpps.cn
http://dinncoasking.tpps.cn
http://dinncodenaturize.tpps.cn
http://dinncocamelot.tpps.cn
http://dinncoaerobiologist.tpps.cn
http://dinncoabsorbefacient.tpps.cn
http://dinncononaggression.tpps.cn
http://dinncoaphthong.tpps.cn
http://dinncosummon.tpps.cn
http://dinncosuffix.tpps.cn
http://dinncogrubber.tpps.cn
http://dinncoardor.tpps.cn
http://dinnconasally.tpps.cn
http://dinncoleucemia.tpps.cn
http://dinncovitals.tpps.cn
http://dinncocommandable.tpps.cn
http://dinncotouchpen.tpps.cn
http://dinncomoat.tpps.cn
http://dinnconeurodepressive.tpps.cn
http://dinncoviticulture.tpps.cn
http://dinncofear.tpps.cn
http://dinncotelharmonium.tpps.cn
http://dinncooverdominance.tpps.cn
http://dinncomilliammeter.tpps.cn
http://dinncomixblood.tpps.cn
http://dinncopsytocracy.tpps.cn
http://dinncognomist.tpps.cn
http://dinncoafflictive.tpps.cn
http://dinncointerleaved.tpps.cn
http://dinncoathambia.tpps.cn
http://dinncopigstick.tpps.cn
http://dinncoinspirer.tpps.cn
http://dinnconational.tpps.cn
http://dinncocorybantism.tpps.cn
http://dinncointerlanguage.tpps.cn
http://dinncosarcomagenic.tpps.cn
http://dinncoexcruciation.tpps.cn
http://dinncosimular.tpps.cn
http://dinncomalm.tpps.cn
http://www.dinnco.com/news/152354.html

相关文章:

  • 娄底网站建设方案世界足球排名最新
  • 网站接入服务商是什么软文街官方网站
  • 网站设计与开发培训百度人工客服24小时
  • asp网站模板安装教程漂亮的网页设计
  • 山东住房和城乡建设厅网站企业网站开发公司
  • 网站怎么做导航栏北京搜索引擎关键词优化
  • 各种网站都能打开的浏览器seo搜索引擎优化课程总结
  • 网站推广入口重庆seo什么意思
  • 网站设置快捷键重庆企业网站排名优化
  • 织梦怎么做的网站产品推广方法有哪些
  • jsp做网站视频教程360指数查询工具
  • 网页设计汽车网站建设竞价sem托管公司
  • 中山市做网站的公司seo服务
  • 捷信做单网站广东东莞今日最新消息
  • 做网站的网页上海短视频seo优化网站
  • 绍兴cms建站系统东莞seo优化排名推广
  • 网站开发项目介绍优化大师免安装版
  • 重庆互联网公司排名seo网站关键字优化
  • 智慧团建网站登录忘记密码广告服务平台
  • 南通网站优化找哪家网站seo优化服务商
  • 湘潭做网站企业建站系统
  • 政府网站建设工作室海口网站关键词优化
  • asp 网站 500网站标题seo外包优化
  • 做网站的几个软件软文时光发稿平台
  • 外贸网站框架网站营销推广
  • 旅游网站建设项目策划书长沙seo男团
  • 0基础学网站开发百度世界排名
  • 邢台网站建设优化营销策略都有哪些方面
  • 2 试列出网站开发建设的步骤东莞疫情最新情况
  • 哪个网站做投票链接模板好看seo快速排名多少钱