I'm learning data structures, and I'm building an AVL tree class. I want to traverse the tree by saving the elements in one string. I already built the three functions that traverse over the tree in {inorder,preorder,postorder} recursively on the console. I wonder how I can modify the code to load the result into a string, and not the console.
I will post the code for postorder down here:
void printPostorder(Node root) { // prints the tree in post order left right root
if (root == null)
return;
printPostorder(root.left);
printPostorder(root.right);
System.out.print(root.element + " ");
}