|   | How should a tree be packed into an array? | 



| 
 
 |  | 
create(), destroy(), … maintenance
        operations.
  add(data) and data remove() manipulation operations.
    size(), empty(), data top(), … query
        operations.
  Heap.create(T a[], unsigned n)
Heap.create(Heap<T> h1, Heap<T> h2)
Heap.merge(Heap<T> h)

| i = count++ d[i] = e while i ≠ 0 p = (i - 1)/2 if d[p] ≥ d[i], break swap(d[p], d[i]) i = p 
 | 
 | 


public T take()
  final T o = heap[0]
  heap[0] = heap[--count]
  pushDown(0)
  return o
private void pushDown(int p)
  final int children [] = 
    new int [] { 2*p + 1, 2*(p + 1) };
  for (int c: children)
    if (c < count) ∧ (heap[p] < heap[c])
      swap(p, c)
      pushDown(c)
| This page last modified on 2010 November 16. |