leftand 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 if(rightchild currentsize &/(rightchild exists?heaparray[leftchildidata heaparray[rightchildidatalargerchild rightchildelse largerchild leftchild/top >largerchildif(top idata >heaparray[largerchildidatabreak/shift child up heaparray[indexheaparray[largerchild]index largerchild/go down /end while heaparray[indextop/index <root /end trickledown(on exiting the loop we need only restore the node stored in top to its appropriate positionpointed to by index key change once we've created the trickledown(and trickleup(methodsit' easy to implement an algorithm to change the priority (the keyof node and then trickle it up or down to its proper position the change(method accomplishes thispublic boolean change(int indexint newvalueif(index=currentsizereturn falseint oldvalue heaparray[indexidata/remember old heaparray[indexidata newvalue/change to new if(oldvalue newvaluetrickleup(index)else trickledown(index)return true/if raised/trickle it up /if lowered/trickle it down