【发布时间】:2018-02-23 17:09:22
【问题描述】:
输入:(A(B(D(E)(F)))(C)(K)) 我目前有两个函数,这给了我一个输出:
一个
乙
C
K
乙
D
D
E
F
E
没有
但是我需要这样的输出:
a: b c k
b: d
c:
克:
d: e f
e:
f:
或
一个
b s k
d
e f
(defun print-children (s)
(cond ((null (caar (cdr s))) nil)
(t (print (caar (cdr s))) (print-children (cdr s)))))
(defun print-tree (s)
(cond ((null s) nil)
((atom (car s)) (print (car s)) (print-children s) (print-tree (cdr s)))
(t (print-tree (car s)))))
【问题讨论】:
-
我不明白这个问题。 'all from the new line' - 这是什么意思?您的问题缺少预期输入和输出的有用示例。
-
@RainerJoswig 改了,更清楚了吗?
-
@RainerJoswig 新加入堆栈,忘记添加所有信息
-
这些函数应该做什么?我可以阅读代码,但例如我不知道您打算用 PRINT-LEVEL 做什么。
-
@RainerJoswig 打印级别(我将其重命名为 print-children)打印主节点的直接子节点。整个问题在于打印一棵树 BREADTH FIRST。
标签: recursion printing tree lisp common-lisp