This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
balL (T B t1 y (T B t2 z t3)) = balance' (T B t1 y (T R t2 z t3)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
balL (T B t1 y (T R (T B t2 u t3) z t4@(T B l value r))) = | |
T R (T B t1 y t2) u (balance' (T B t3 z (T R l value r))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
balL (T B (T R t1 x t2) y t3) = T R (T B t1 x t2) y t3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
balL :: Tree a -> Tree a | |
balR :: Tree a -> Tree a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
delete :: (Ord a) => a -> Tree a -> Tree a | |
delete x t = makeBlack $ del x t | |
where makeBlack (T _ a y b) = T B a y b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
del :: (Ord a) => a -> Tree a -> Tree a | |
del x t@(T _ l y r) | |
| x < y = delL x t | |
| x > y = delR x t | |
| otherwise = fuse l r |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 color a x b = T color a x b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T B (T R (T R a x b) y c) z d | |
T B (T R a x (T R b y c)) z d | |
T B a x (T R (T R b y c) z d) | |
T B a x (T R b y (T R c z d)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
insert :: (Ord a) => a -> Tree a -> Tree a | |
insert x s = makeBlack $ ins s | |
where ins E = T R E x E | |
ins (T color a y b) | |
| x < y = balance color (ins a) y b | |
| x == y = T color a y b | |
| x > y = balance color a y (ins b) | |
makeBlack (T _ a y b) = T B a y b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
member :: (Ord a) => a -> Tree a -> Bool | |
member x E = False | |
member x (T _ a y b) | |
| x < y = member x a | |
| x == y = True | |
| otherwise = member x b |