Show the splay tree that results from a search 1 operation o
Solution
Object Binary Tree java class
compareTo()
operate()
visit()
compareTo():
The compareTo() method is used to compare two nodes based on the values those nodes are holding
The compareTo() methods compares the current nodes with the referenced node,
and based uopn the given values, it returns
0, if both nodes are equal
> 0, if first node\'s value is greater than second node\'s value
< 0, if first node\'s value is smaller than second node\'s value
For example, there are two nodes objA and objB
and if objA holds value 10 and objB holds 20
then objA.compareTo(objB) sould return -10
operate():
The operate() method is used to do some operation with refrenced node.
For example, in given Object Binary Tree class, the operate() method is used
in insertBSTDup() method, which would insert a duplicate node (say \"objO\")
whereever in the tree it find the same value of \"objO\"
So the tree is traversed until the node having same value as that of \"objO\" is found.
Then the operation (inserting duplicate node) is performed.
visit():
The visit() method is used to fetch the data which a tree node holds
It is used in preTrav, inTrav, postTrav methods, which are used to traverse the tree
preTrav =
1 print the value of current node
2 traverse to left child node, unless there are no more left child node
3 traverse to right child node
4 repeat from 1
inTrav =
1 traverse to left child node, unless there are no more left child node
2 print the value of current node
3 traverse to right child node
4 repeat from 1
PostTrav =
1 traverse to left child node, unless there are no more left child node
2 traverse to right child node
3 print the value of current node
4 repeat from 1
