Should a new heap have 2 items? why does a cleared heap have 1?
public BinaryHeapM ( int numberOfElements ) {
binaryHeap = new NodeRun[numberOfElements];
numberOfItems = 2;
}
public void Clear () {
numberOfItems = 1;
}
The first add will add at 2
binaryHeap[numberOfItems] = node;
But will then compare against its parent at position 1 (in the bubbleup code) which has never been written to…