One extremely tricky solution is always to ensure that your algorithm thinks every node has two children. Do this by placing a sentinel, a value higher than any in the heap, at the spot after the heap ends, at the start of each percolate down when the heap size is even.