babu bhai
babu bhai

Reputation: 3

Return value from inorder binary tree method

I should get the values from the inorder method and then store them in a text file. How can i achieve it in the following code? If i use return to return values to another write method to store in a text file instead of System.out.println, it won't go to the next root.getRight() statement. Any help?

private String inorder(TreeNode root) {

        if(root.getLeft()!=null){
            inorder(root.getLeft());
        }

        stringConcatenation += root.getData());

        if(root.getRight()!=null){
            inorder(root.getRight());
        }

        return  stringConcatenation;  
    }   // end of inorder()

Upvotes: 0

Views: 944

Answers (1)

Scott Hunter
Scott Hunter

Reputation: 49883

You could concatenate the results from each recursive call with the root value to get a string with the whole list, which could then be returned.

Upvotes: 1

Related Questions