[prev] 9 [next]

Insertion with Heaps (cont)

Insertion into heap:

void insert(Heap h, Item it)
{
   assert(h->nitems < h->nslots);
   h->nitems++;
   h->items[h->nitems] = it;
   fixUp(h->items, h->nitems);
}

Always start new item at next available position on bottom level
(corresponds to next free element in the array (i.e. items[nitems])