Skip to content

Commit 63853f6

Browse files
committed
tree rotations
1 parent 4a8a753 commit 63853f6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ITMOPrelude/Tree.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ addToLeftLeaf x Leaf = Node x Leaf Leaf
1818
addToRightLeaf x (Node a l r) = Node a l (addToRightLeaf x r)
1919
addToRightLeaf x Leaf = Node x Leaf Leaf
2020

21-
-- rotations? which rotations
21+
leftRotate (Node x l (Node y l' r')) = Node y (Node x l l') r'
22+
leftRotate n = error "leftRotate: Incorrect tree"
23+
24+
rightRotate (Node x (Node y l' r') r) = Node y l' (Node x r' r)
25+
rightRotate n = error "rightRotate: Incorrect tree"
2226

2327
tmap :: (a -> b) -> Tree a -> Tree b
2428
tmap f Leaf = Leaf
2529
tmap f (Node x l r) = Node (f x) (tmap f l) (tmap f r)
2630

2731
tfold :: (a -> b -> b) -> b -> Tree a -> b
2832
tfold f z Leaf = z
29-
tfold f z (Node x l r) = f x (tfold f (tfold f z r) l)
33+
tfold f z (Node x l r) = f x (tfold f (tfold f z r) l)
34+

0 commit comments

Comments
 (0)