Same fringe: Difference between revisions
→{{header|Haskell}}: Applied hindent, + slight visual pruning of the test
m (improved output) |
(→{{header|Haskell}}: Applied hindent, + slight visual pruning of the test) |
||
Line 1,029:
To get the fringe, we can simply use the solution for [[Flatten a list#Haskell|Flatten a list]], slightly modified for a binary tree instead of a general tree:
<lang haskell>data Tree a
= Leaf a
deriving (Show, Eq)▼
| Node (Tree a)
(Tree a)
fringe :: Tree a -> [a]
Line 1,036 ⟶ 1,039:
fringe (Node n1 n2) = fringe n1 ++ fringe n2
sameFringe
:: (Eq a)
=> Tree a -> Tree a -> Bool
sameFringe t1 t2 = fringe t1 == fringe t2
main :: IO ()
main = do
(Node
z = Node (Leaf 1) (Node (Leaf 2) (Node (Node (Leaf 4) (Leaf 3)) (Leaf 5)))
▲{{out}}
<pre>True
True
|