public void add( E element ) {
    if ( element == null ) {
      throw new NullPointerException();
    }

    // insert the new element as the new rightmost leaf
    if ( size == heap.length ) {
      resize();
    }
    heap[size] = element;
    size++;
    int child = size - 1;
    int parent = ( child - 1 ) / 2;

    // while the new element has a parent and the new element
    // is less than its parent
    while ( ( child != TOP ) &&
            ( comparator.compare( heap[child],
                                  heap[parent] ) < 0 ) ) {
      // swap the parent and child elements
      E temp = heap[parent];
      heap[parent] = heap[child];
      heap[child] = temp;
      child = parent;
      parent = ( child - 1 ) / 2;
    }
  }