Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I searched and didn't find a way to do this, if it exists, can you guys help me how to do it?
根据您的确切堆布局,您可能有两个候选者(假设您的根是最小元素,第二层是最大元素)。
选择最大的一个,并将其替换为堆的最后一个元素 - 就像使用常规堆一样 - 并执行向下堆修复。就像普通堆一样,从位置 1 或 2 而不是 0 开始,然后像在 min-max-heap 中一样下降到级别。