c++ - Printing Tree Vertically -


Any idea how to print a tree like this?

  2 / \ / \ / \ / \ 7 5 / \ \ / \ 2 6 9 / \ / 5 8 4  

Horizontal solution works well because you use deep search (as you've shown) to create a tree from each subtitle. , Which the console aligns well in the form of a line at a time.

The vertical solution is more difficult, because you need to know all the nodes at the end of the tree to calculate the full width. Therefore, you need to analyze the tree, collect data and then start plotting.

The second option, though perhaps not "elegant" (based on definition), would be to use something like a curses library, in which the performance columns and rows have interchangeable concepts.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -