开发者

How to display hierarchy levels with text

开发者 https://www.devze.com 2023-02-18 02:56 出处:网络
As the title says. It\'s a tree data structure that I need to display using only text. --something ----like

As the title says. It's a tree data structure that I need to display using only text.

--something

----like

----thi开发者_如何学Pythons

------but more visually

--------understandable

What is the de facto way to do this as used maybe by CLIs etc?


There is a property on the TreeNode class called level. You could loop through all nodes and add a number of tab characters to the string for the node based on level. This would then indent your text according to the level of the node in the string.

0

精彩评论

暂无评论...
验证码 换一张
取 消