notes public class leftistheap extends binarytree implements mergeablepriorityqueue protected int nullpathlength/program leftistheap fields merging leftist heaps in order to merge two leftist heapssay and declared as follows mergeablepriorityqueue new leftistheap ()mergeablepriorityqueue new leftistheap () invoke the merge method like thish merge ( )the effect of the merge method is to take all the nodes from and to attach them to thus leaving as the empty heap in order to achieve logarithmic running timeit is important for the merge method to do all its work on the right sides of and it turns out that the algorithm for merging leftist heaps is actually quite simple to begin withif is the empty heapthen you can simply swap the contents of and otherwiselet us assume that the root of is larger than the root of then you can merge the two heaps by recursively merging with the right subheap of after doing soit may turn out that the right subheap of now has larger null path length than the left subheap this you rectify by swapping the left and right subheaps so that the result is again leftist on the other handif initially has the smaller rooti simply exchange the roles of and and proceed as above figure illustrates the merge operation in this examplei wish to merge the two trees and shown in figure (asince has the larger rootit is recursively merged with the right subtree of the result of that merge replaces the right subtree of as shown in figure (bsince the null path length of the right subtree is now greater than the leftthe subtrees of are swapped giving the leftist heap shown in figure ( lovely professional university