it's first option about swap root with an node..
but how to do it? i have no clue..
and here is my node class:
public class BinaryTreeNode<T>
{
protected T element;
protected BinaryTreeNode<T> left, right;
protected int counter;
protected BinaryTreeNode<T> node;
BinaryTreeNode (T obj)
{
element = obj;
left = null;
right = null;
counter = 0;
}
BinaryTreeNode (T obj, int hits)
{
element = obj;
left = null;
right = null;
this.counter = hits;
}
public void setLeft(BinaryTreeNode<T> left)
{
this.left = left;
}
public void setRight(BinaryTreeNode<T> right)
{
this.right = right;
}
public BinaryTreeNode<T> getLeft()
{
return left;
}
public BinaryTreeNode<T> getRight()
{
return right;
}
public T getElement()
{
return element;
}
public int numChildren()
{
int children = 0;
if (left != null)
children = 1 + left.numChildren();
if (right != null)
children = children + 1 + right.numChildren();
return children;
}
public void increment()
{
counter++;
}
}