数据结构和算法 - 如何用java实现链式堆?
怪我咯
怪我咯 2017-04-17 17:33:14
0
1
398

我知道堆是一个特殊的二叉树,但是为什么每次向堆中插入元素时都需要重排序?
用java代码如何实现?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
迷茫

Heaps not only include binary heaps, but also triple heaps and other multi-forked heaps. The reason why elements must be reordered every time they are inserted into the heap is because of the characteristics of the heap itself. If a binary heap is a minimum heap, then every time The two child nodes of a node should both be larger than itself. When all nodes in the heap are less than or equal to its two child nodes, the heap is in order; when you insert a new node, this order of the heap will be destroyed. status, so it needs to be reordered. As for the Java implementation version, you can search it online. It is easy to find. The heap implementation of JDK is the java.util.PriorityQueue class. You can check it out

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!