diff options
-rw-r--r-- | H61.hs | 5 | ||||
-rw-r--r-- | H62.hs | 14 | ||||
-rw-r--r-- | H63.hs | 8 | ||||
-rw-r--r-- | Tree4.hs | 6 |
4 files changed, 33 insertions, 0 deletions
@@ -0,0 +1,5 @@ +import Tree + +countLeaves Empty = 0 +countLeaves (Branch _ Empty Empty) = 1 +countLeaves (Branch _ t1 t2) = countLeaves t1 + countLeaves t2 @@ -0,0 +1,14 @@ +import Tree +-- import Tree4 + +leaves Empty = [] +leaves (Branch x Empty Empty) = [x] +leaves (Branch x t1 t2) = leaves t1 ++ leaves t2 + +internals Empty = [] +internals (Branch x Empty Empty) = [] +internals (Branch x t1 t2) = [x] : internals t1 ++ internals t2 + +atLevel Empty _ = [] +atLevel (Branch x _ _) 1 = [x] +atLevel (Branch _ t1 t2) n = atLevel t1 (n-1) ++ atLevel t2 (n-1) @@ -0,0 +1,8 @@ +import Tree + +completeBinaryTree n = makeTree 1 + where makeTree x + | x > n = Empty + | otherwise = Branch 'x' (makeTree (2*x)) (makeTree (2*x+1)) + +isCompleteBinaryTree diff --git a/Tree4.hs b/Tree4.hs new file mode 100644 index 0000000..533899c --- /dev/null +++ b/Tree4.hs @@ -0,0 +1,6 @@ +module Tree4 where + +import Tree + +tree4 = Branch 1 (Branch 2 Empty (Branch 4 Empty Empty)) + (Branch 2 Empty Empty) |