You are viewing a single comment's thread. Return to all comments →
To eliminate the trailing space before or after the printed result I used the following:
void preOrder(Node root) { if(root == null) return; System.out.print(root.data); if(root.left != null){ System.out.print(" "); preOrder(root.left); } if(root.right != null){ System.out.print(" "); preOrder(root.right); } }
Note: it might not be required for passing the tests successfully, but just for fun.
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Preorder Traversal
You are viewing a single comment's thread. Return to all comments →
To eliminate the trailing space before or after the printed result I used the following:
Note: it might not be required for passing the tests successfully, but just for fun.