I'm stuck with returning BS tree put into an array. I guess the problem is that I'm not passing around the counter to determine where the next free index is (I was planning to make the counter as the first element of array to make it easier). Any suggestions?
public int[] returnInOrderTraversal(){
int[] arr = new int[getSize()+1];
if (rootNode != null)
{
rootNode.returninOrderTraversal(arr);
}
return arr;
}
public void returninOrderTraversal(int[] arr){
if(this.getLeftChild() != null)
{
this.getLeftChild().returninOrderTraversal(arr);
}
arr[arr[0]++] = this.getValue();
if (this.getRightChild() != null)
{
this.getRightChild().returninOrderTraversal(arr);
}
}