【发布时间】:2016-03-06 19:01:53
【问题描述】:
我为二叉树编写了一个简单的中序遍历函数 (toList1)。但是,我担心它的复杂性(内存/时间)。有没有更好的实现方式?
data Tree a = Empty | Node a (Tree a) (Tree a)
toList1 :: (Tree a) -> [a]
toList1 Empty = []
toList1 (Node x lx rx) = (toList lx) ++ [x] ++ (toList rx)
【问题讨论】:
-
您的问题更适合codereview.stackexchange.com。但是,这里有一个提示:您可以在最后一个等式中生成the concatenate vanish。
标签: haskell binary-tree inorder