Defining methods in TreeComparable Interface

I have the TreeComparable Interface and BinaryTree class, but I am having difficulty with understanding how to define the operate method within my class. At the end of the insertBSTDuplicate method, the operate is method is called, but I cannot figure out from the operation how operate needs to be defined. I have tried different things and none of them seem to work.

Re: Defining methods in TreeComparable Interface

I don't think comparing two binary search trees is that easy, i.e. two infix iterations over two trees might have the same result while the two trees can be entirely different. If you have to take that in account, there's no PTO (Partial Total Order).

kind regards,

Jos

I have the stamina of a seal; I lie on the beach instead of running on it.

Re: Defining methods in TreeComparable Interface

Assume two trees are guaranteed to be red-black and any given traversal of one tree produces the same results of another. Can one declare the trees to have the same parent-child relationships? Can this red-black structure be enforced (perhaps via some abstract class or interface requirement)? I admit I haven't given this any thought. Just thought I ask the questions in case someone else has.

Re: Defining methods in TreeComparable Interface

Originally Posted by jim829

Assume two trees are guaranteed to be red-black and any given traversal of one tree produces the same results of another. Can one declare the trees to have the same parent-child relationships? Can this red-black structure be enforced (perhaps via some abstract class or interface requirement)? I admit I haven't given this any thought. Just thought I ask the questions in case someone else has.

I gave it some thoughts ;-) If the infix traversals compare unequal, you know the order of the two trees L and R; otherwise, structurally compare L against R; the restriction of red-black trees is unneeded; if the roots of the trees compare unequal, you're done; otherwise compare both left subtrees etc.

kind regards,

Jos

I have the stamina of a seal; I lie on the beach instead of running on it.

Re: Defining methods in TreeComparable Interface

From what I understand when the left and right child of the parent tree node are equal to each other, the operate method is called. But as for the operate method, I am unsure how that is defined when implemented.