Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
18
Task/Algebraic-data-types/Haskell/algebraic-data-types.hs
Normal file
18
Task/Algebraic-data-types/Haskell/algebraic-data-types.hs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
data Color = R | B
|
||||
data Tree a = E | T Color (Tree a) a (Tree a)
|
||||
|
||||
balance :: Color -> Tree a -> a -> Tree a -> Tree a
|
||||
balance B (T R (T R a x b) y c ) z d = T R (T B a x b) y (T B c z d)
|
||||
balance B (T R a x (T R b y c)) z d = T R (T B a x b) y (T B c z d)
|
||||
balance B a x (T R (T R b y c) z d ) = T R (T B a x b) y (T B c z d)
|
||||
balance B a x (T R b y (T R c z d)) = T R (T B a x b) y (T B c z d)
|
||||
balance col a x b = T col a x b
|
||||
|
||||
insert :: Ord a => a -> Tree a -> Tree a
|
||||
insert x s = T B a y b where
|
||||
ins E = T R E x E
|
||||
ins s@(T col a y b)
|
||||
| x < y = balance col (ins a) y b
|
||||
| x > y = balance col a y (ins b)
|
||||
| otherwise = s
|
||||
T _ a y b = ins s
|
||||
Loading…
Add table
Add a link
Reference in a new issue