【发布时间】:2015-06-03 02:32:45
【问题描述】:
在 Haskell 中,可以通过以下两种方式之一定义二叉树:
data Tree a = Empty | Branch a (Tree a) (Tree a)
或
data Tree a = Leaf a | Branch (Tree a) (Tree a)
选择其中一个有什么好处?在哪些情况下,一种树结构比另一种更适合?
【问题讨论】:
-
data Tree a = Leaf a | Branch (Tree a) a (Tree a)应该也能正常工作吧?
标签: algorithm haskell data-structures tree