技巧,知识积累,持续更新

堆的构建: 以大根堆为例

参考

  1. 找到堆中最后一个父节点
  2. 对比当前父节点和左右子节点的大小,最大的和较小的交换。
  3. 数组逆序到上一个父节点,执行第二步以后,如果交换的子节点还有子节点,执行第二步到叶节点
  4. 执行到根节点结束
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信