数据结构中的最大堆插入
我们将在此处了解如何插入元素到二进制最大堆数据结构中。假设初始树形结构如下 −
插入算法
insert(heap, n, item) − Begin if heap is full, then exit else n := n + 1 for i := n, i > 1, set i := i / 2 in each iteration, do if item <= heap[i/2], then break heap[i] = heap[i/2] done end if heap[i] := item End
示例
假设我们要向堆中插入 30 −
广告