Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Trees where
- --import Prelude(Int(..), Show(..))
- data Nat = Zero | Succ Nat
- deriving (Show, Eq, Ord)
- data Tree a = Leaf a | Branch (Tree a) a (Tree a)
- deriving Show
- data TreeTwo b = Leaft b | Brancht (Tree b) (Tree b)
- deriving Show
- treeOne = Branch (Branch (Leaf 14) 20 (Leaf 21)) 25 (Branch (Leaf 29) 37 (Branch (Leaf 43) 50 (Leaf 52)))
- treeTwo = Brancht (Brancht (Leaft 14) (Leaft 21)) (Brancht (Leaft 29) (Brancht (Leaft 43) (Leaft 52)))
- --переворот
- reverseTree :: Tree a -> Tree a
- reverseTree (Branch left value right) = (Branch (reverseTree right) value (reverseTree left))
- reverseTree (Leaf value) = Leaf value
- --глубина
- depth :: Tree a -> Nat
- depth (Leaf a) = Succ Zero
- depth (Branch left value right) = Succ(max (depth left) (depth right))
- --список
- leaves :: Tree a -> [a]
- leaves (Leaf a) = [a]
- leaves (Branch left a right) = leaves left ++ leaves right
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement