Three variables, leftchild, rightchild, and root, are initialized as follows:
leftchild=0rightchild=0root=1
The following steps are performed to delete a max-heap:
- The element at the root node is temporarily assigned to the n variable.
- The last element of the heap is placed at the root node.
- If the value of the last index location is 1 or 2, that is, if the heap has only 1 or 2 elements left, then return to the caller with the n variable.
- Since the last element is placed at the root node, reduce the size of the heap by 1.
- To maintain the max-heap property, repeat steps 6 through 9 while rightchild <=last. Recall, the property of the max-heap is that the value of the parent node should be always larger than its children ...