Solved
help with binarytree conversion
Posted on 2006-10-24
Hi,
I'm trying to convert linked representation of a binary tree to its array format, but I'm having problem calculating the last index for the array. How do I keep track of the index since "last" only gives number of elements ? thanks
public T[] converttoarray(Node<T> root, T[] a, int i)
{
if(root != null) {
a[i] = root.element;
last++;
converttoarray(root.left, ar, 2*i + 1);
converttoarray(root.right, ar, 2*i + 2);
}
return a;
}