Write an efficient algorithm to print a binary tree structure in standard output.

Print Binary Tree        Generated Binary Tree

 
For example, a binary tree on the left can be displayed as a binary tree on the right programmatically. The following code in C++, Java, and Python serves as an excellent helper function to tree problems for printing a binary tree or BST:

C++


Download  Run Code

Java


Download  Run Code

Python


Download  Run Code