当前位置:网站首页>PriorityQueue类的使用及底层原理
PriorityQueue类的使用及底层原理
2022-08-04 19:51:00 【像你这样的】
目录
Java中PriorityQueue通过二叉小顶堆实现,可以用一棵完全二叉树表示


上面数组对应的完全二叉树是
从上面二叉树这个图中, 我们可以发现规律 :
如果一个节点对应的数组下标是index, 则我们可以计算出他的左节点的数组下标, 右节点的数组下标, 父节点的数组下标
左节点的数组下标 : index * 2 + 1
右节点的数组下标 : index * 2 + 2
父节点的数组下标 : (index - 1) / 2
因此我们可以简单的获取值的左右节点和父节点的值, 用于值与值间的对比, 替换
add()方法的底层原理 :
add()方法中调用的就是offer()方法, 直接看offer()方法


poll()方法的底层原理 :

边栏推荐
- C#的Dictionary字典集合按照key键进行升序和降序排列
- How to monitor code cyclomatic complexity by refactoring indicators
- getBoundingClientRect
- Spark提交参数说明和常见优化
- 拥抱Cmake小朋友 简单又实用,但是不灵活
- Switch node version and switch npm source tool
- 简易数据缓存层的建立
- SAP UI5 ensures that the control id is globally unique implementation method
- 正畸MIA微种植体支抗技术中国10周年交流会在沈举办
- awk statistical difference record
猜你喜欢

The list of Kubernetes - watch mechanism

蚂蚁集团时序数据库CeresDB正式开源

刷题-洛谷-P1200 你的飞碟在这儿Your Ride Is Here

Chrome安装zotero connector 插件

Seata source code analysis: various message processing processes of seata server

VQ Realization of Wavelet Extraction Features

按需视觉识别:愿景和初步方案

PostgreSQL的 SPI_接口函数

Notepad++更改显示背景

华为交换机:STP测试实验
随机推荐
如何使用 jMeter Parallel Controller - 并行控制器以及一些常犯的错误
备忘录模式
visual studio 与 visual studio code
程序员如何在职场上少走弯路?
【ASP.NET Core】 中间件
03 ts类型缩小,函数
带你了解数据分布式存储原理
【AGC】构建服务1-云函数示例
如何手动下载并安装 Visual Studio Code 的 SAP Fiori tools - Extension Pack
【Attention 演变史】RNN的产生、架构、推广、问题(第一弹)
How to add custom syntax to MySQL?
[Latest Information] 2 new regions will announce the registration time for the soft exam in the second half of 2022
华为WLAN技术:AP上线及相关模板的配置实验
小软件大作用 | 如何省时省力进行Gerber图层快速对比?
使用 Chrome 开发者工具 coverage 功能分析 web 应用的渲染阻止资源的执行分布情况
PG网络传输安全SSL介绍及使用示例
Chrome 开发者工具 performance 标签页的用法
Order of lds links
PostgreSQL的 SPI_接口函数
二叉树的前序遍历