Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的职业生涯中经常出现的一个问题是我有某种数据结构(可能是 s 表达式),我想以人类可读的形式打印它,并带有合理的缩进选择。
是否有书籍或博客文章描述了如何优雅地做到这一点?我对算法感兴趣的不仅仅是一个特定的库。
S-Exps 等价于树结构,如果你可以漂亮地打印一棵树,你就可以漂亮地打印一个 s-exp。
例如,比较:
(tree (value 89) (tree (value 9) nil nil) (tree (value 456) nil nil))
到:
89 +- 9 +- 456
该算法是相同的,唯一的区别是您要打印的周围数据的数量。
本文描述了一种用于漂亮打印树的算法
这个描述了一种用于编程语言的漂亮打印机