private void fixHeap( int parent ) {

    int child = smallestChild( parent );

    // while the parent has a child and the parent's element
    //  is greater than the element in either child
    while ( ( child != NO_CHILD ) &&
            ( comparator.compare( heap[child],
                                  heap[parent] ) < 0 ) ) {
      //invariant: the parent's children are roots of
      //   valid heaps
      //swap the parent's element with the element of the
      //  smaller of its children
      E temp = heap[parent];
      heap[parent] = heap[child];
      heap[child] = temp;
      //invariant: the parent and its children are a
      //    now valid heap
      // move parent to the swapped child
      parent = child;
      child = smallestChild( parent );
    }
    //loop postcondition: the binary tree rooted at node is
    //  a valid heap
  }