Binary Search Tree into array
Hi, i need to store the nodes of a given binary search tree into an array in ascending order. i have come up with this:
publicstaticint[] collectNodesHelper(tree t){
int totalNodes = 0;
if(!isempty(t)){
collectNodesHelper(Left(t));
totalNodes = totalNodes + 1;
collectNodesHelper(Right(t));
}
int[] arr =newint[totalNodes];
for (int i=0; i<totalNodes; i++){
arr[i] = Root(t);
}
return arr;
}
which i'm fairly sure should work, but i am unsure about how to return - because where the statement is now, it says it cannot access variable arr.>

