ifrightchild currentsize &/(rightchild exists?heaparray[leftchildgetkey(heaparray[rightchildgetkey(largerchild rightchildelse largerchild leftchild/top >largerchildif(top getkey(>heaparray[largerchildgetkey()break/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 after we've created the trickledown(and trickleup(methodswe can easily 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[indexgetkey()/remember old heaparray[indexsetkey(newvalue)/change to new if(oldvalue newvaluetrickleup(index)else trickledown(index)return true/end change(/if raised/trickle it up /if lowered/trickle it down this routine first checks that the index given in the first argument is validand if sochanges the idata field of the node at that index to the value specified as the second argument