heaps finallywhen the loop has exitedthe newly inserted nodewhich has been temporarily stored in bottomis inserted into the cell pointed to by index this is the first location where it' not larger than its parentso inserting it here satisfies the heap condition removal the removal algorithm is also not complicated if we subsume the trickle-down algorithm into its own routine we save the node from the rootcopy the last node (at index currentsize- into the rootand call trickledown(to place this node in its appropriate location public node remove(/delete item with max key /(assumes non-empty listnode root heaparray[ ]/save the root heaparray[ heaparray[--currentsize]/root <last trickledown( )/trickle down the root return root/return removed node /end remove(this method returns the node that was removedthe user of the heap usually needs to process it in some way the trickledown(routine is more complicated than trickleup(because we must determine which of the two children is larger firstwe save the node at index in variable called top if trickledown(has been called from remove()index is the rootbutas we'll seeit can be called from other routines as well the while loop will run as long as index is not on the bottom row--that isas long as it has at least one child within the loop we check if there is right child (there may be only left)and if socompare the children' keyssetting largerchild appropriately then we check if the key of the original node (now in topis greater than that of largerchildif sothe trickle-down process is complete and we exit the loop public void trickledown(int indexint largerchildnode top heaparray[index]while(index currentsize/ int leftchild *index+ int rightchild leftchild+ /save root /while node has at /least one child/find larger child