File tree 2 files changed +10
-0
lines changed
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ dependencies:
23
23
- base >= 4.11 && < 5
24
24
- random
25
25
- QuickCheck
26
+ - containers
26
27
27
28
library :
28
29
source-dirs : src
@@ -38,6 +39,7 @@ executables:
38
39
dependencies :
39
40
- hs
40
41
- random
42
+ - containers
41
43
42
44
tests :
43
45
hs-test :
Original file line number Diff line number Diff line change @@ -64,3 +64,11 @@ maxDepth :: Int -> Tree -> Int
64
64
maxDepth d (Branch o a b) = if m > n then m else n where m = maxDepth (d + 1 ) a
65
65
n = maxDepth (d + 1 ) b
66
66
maxDepth d (Leaf a) = d
67
+
68
+ labelTree :: Tree -> Int -> Set Int -> Set Int
69
+ labelTree (Leaf a) n xs = (singleton n) `union` xs
70
+ labelTree (Branch o a b) n xs = (singleton n) `union` (labelTree a (2 * n + 1 ) xs) `union` (labelTree b (2 * n + 2 ) xs)
71
+
72
+ intersectionOfTreeLabels :: Tree -> Tree -> Set Int
73
+ intersectionOfTreeLabels t1 t2 = (labelTree t2 0 empty) `intersection` (labelTree t1 0 empty)
74
+
You can’t perform that action at this time.
0 commit comments