有什么区别
data Tree a = Leaf a | Node (a, Tree a, Tree a) deriving Show
Run Code Online (Sandbox Code Playgroud)
和
data Tree a = Leaf a | Node a (Tree a) (Tree a) deriving Show
Run Code Online (Sandbox Code Playgroud)
注意:节点的括号
我是否正确使用尾递归实现了顺序级别顺序树横向?
inorder (Leaf n) temp = n:temp
inorder (Node (n, left, right)) temp = inorder left (n:inorder right temp)
inorder :: Tree a -> [a] -> [a]
Run Code Online (Sandbox Code Playgroud)
树被声明为
data Tree a = Leaf a | Node (a, Tree a, Tree a) deriving Show
Run Code Online (Sandbox Code Playgroud)
并[2,1,3]在电话inorder three []中返回
three = Node (1, Leaf 2, Leaf 3)
我知道如何获得一对的第一个元素 first (x:_) = x
但是如何获取对列表并返回每个第一项的列表?我是否使用循环或是否有其他语法?
[(1,2),(3,4),(5,6)] gives [1,3,5]
Run Code Online (Sandbox Code Playgroud)