public static Heap insert (Heap heap, int value) { // traverse the tree and assign ranks to everyone labelRank (heap); // then do the actual insertion return insertHelp (heap, value); } public static Heap insertHelp (Heap heap, int value) { // to add a new element to a null heap, create a new object if (heap == null) { return new Heap (value, null, null); } // figure out which side is going to get the new object int choice = LEFT; if (heap.left == null) { choice = LEFT; } else if (heap.right == null) { choice = RIGHT; } else if (heap.left.rank > heap.right.rank) { choice = RIGHT; } // call insertHelp recursively on the appropriate child, // then check for the heap property when the child returns. if (choice == LEFT) { heap.left = insertHelp (heap.left, value); if (heap.value < heap.left.value) { swapContents (heap, heap.left); } } else { heap.right = insertHelp (heap.right, value); if (heap.value < heap.right.value) { swapContents (heap, heap.right); } } return heap; } public static Heap remove (Heap heap) { if (heap == null) return null; // put the primary return value into removedValue removedValue = heap.value; // then fix the broken heap return reheapify (heap); } public static Heap reheapify (Heap heap) { // reheapify by recursively removing an element from // the larger of the two children int larger; // if there are no children, return an empty heap if (heap.left == null && heap.right == null) return null; // larger indicates which of the children is larger if (heap.left == null) { larger = RIGHT; } else { larger = LEFT; if (heap.right != null && heap.right.value > heap.left.value) { larger = RIGHT; } } // steal a value from the larger child and reheapify if (larger == LEFT) { heap.value = heap.left.value; heap.left = reheapify (heap.left); } else { heap.value = heap.right.value; heap.right = reheapify (heap.right); } return heap; } public static void main (String[] args) { Heap heap = null; // generate 100 random numbers and put them in the Heap for (int i = 0; i<100; i++) { int x = (int) (Math.random() * 100); heap = insert (heap, x); System.out.println ("Inserting " + x); } // remove all the items from the Heap while (heap != null) { heap = remove (heap); System.out.println ("Removing " + removedValue); } } 0) why don't we use a constructor to create a heap? (another disadvantage of non-sentinel objects) 1) how do we know when the heap is empty? 2) how does remove indicate an error?