for trees, in traversal methods I want the values to be returned. the method i tried only returns one value.
int inorder(BSTNode r) {
int result = 0 ;
if (r != null) {
inorder(r.getLeft());
result= r.getData();
inorder(r.getRight());
}
return result;
}
this code works perfectly but I want the method to return the values instead
private void inorder(BSTNode r) {
if (r != null) {
inorder(r.getLeft());
System.out.print(r.getData() + " ");
inorder(r.getRight());
}
}