【发布时间】:2017-10-04 12:29:11
【问题描述】:
到目前为止我有这个代码:
data BinaryTree a = Null | Node a (BinaryTree a) (BinaryTree a)
treeLeaves :: BinaryTree a -> [a]
treeLeaves tree = case tree of
Null -> []
Node v t1 t2 -> [] ++ treeLeaves t1 ++ treeLeaves t2
我不确定我做错了什么。它输出一个空列表。
【问题讨论】:
-
在用 Haskell 写之前,请先解释一下你自己会怎么做?您希望程序采取哪些步骤来归还叶子?
-
[] ++ x ++ y是x ++ y。treeLeaves什么时候会返回[]以外的其他内容? -
来自
Node v t1 t2的v参数未在实现中使用。嗯,也许我们可以用它做点什么或使用_而不是分心...
标签: list haskell tree binary-tree