In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to apply heap in Java data structure". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. creation of heap 1. Downward adjustment (take small heap as an example)
Let parent mark the nodes that need to be adjusted, and child marks the left child of parent (Note: if parent has a child, there must be a left child first)
If the left child of parent exists, that is, child < size, do the following until the left child of parent does not exist:
Whether the right child of parent exists, find the youngest of the left and right children, and let child mark it.
Compare parent with the child of a younger child if:
The parent is less than the younger child's child, otherwise the adjustment ends: exchange the parent with the younger child's child. After the exchange is completed, the larger elements in the parent move downward, which may cause the subtree not to satisfy the nature of the heap, so you need to continue to adjust downward, that is, parent = child;child = parent*2+1; and then continue 2.
Public void shiftDown (int [] elem,int parent,int len) {int cur=parent*2+1; while (cur)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.