My tree class:
public class BT<E>{
E value;
BT<E> left, right;
public BT(E value)
{
this.value=value;
}
public BT (E value, BT left, BT right)
{
this.value = value;
this.left = left;
this.right = right;
}
public Tree getLeft(){
return left;}
public Tree getRight(){
return right;}
public void setLeft(Tree ln){
left = ln;}
public void setRight(Tree rn){
right = rn;}
public Tree getParent(){
return this;}
I recursively generate two trees in my main method. T1 the main tree and T2 a random subtree.
I am able to randomly select a node in T1 however I am not able to replace T2 AT the randomly selected node in T1.
Since at a given node I'm only able to setLeft() and setRight() I do not know how to set at the current node I am at.
Even a nudge in the right direction would be appreciated.
[EDIT] To clarify, based on the structure of my tree, how would one go about replacing a specific node with another seperate tree (sub-tree).