summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--H61.hs5
-rw-r--r--H62.hs14
-rw-r--r--H63.hs8
-rw-r--r--Tree4.hs6
4 files changed, 33 insertions, 0 deletions
diff --git a/H61.hs b/H61.hs
new file mode 100644
index 0000000..64dd9e3
--- /dev/null
+++ b/H61.hs
@@ -0,0 +1,5 @@
+import Tree
+
+countLeaves Empty = 0
+countLeaves (Branch _ Empty Empty) = 1
+countLeaves (Branch _ t1 t2) = countLeaves t1 + countLeaves t2
diff --git a/H62.hs b/H62.hs
new file mode 100644
index 0000000..b835b20
--- /dev/null
+++ b/H62.hs
@@ -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)
diff --git a/H63.hs b/H63.hs
new file mode 100644
index 0000000..03f081e
--- /dev/null
+++ b/H63.hs
@@ -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)