【发布时间】:2014-03-12 23:36:46
【问题描述】:
我坚持将返回的 BS 树放入一个数组中。我想问题是我没有绕过计数器来确定下一个空闲索引在哪里(我打算将计数器作为数组的第一个元素以使其更容易)。有什么建议吗?
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);
}
}
【问题讨论】:
标签: java arrays tree binary-tree binary-search-tree