summaryrefslogtreecommitdiff
path: root/H57.hs
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-04-05 21:22:20 +0800
committerJoe Zhao <ztuowen@gmail.com>2015-04-05 21:22:20 +0800
commit897055910d8bda98b3454b6f66ad697edc4676b3 (patch)
tree3cdb8b63aa195aea8c51497f06a41a50fba9ea3d /H57.hs
parentef5f19da8865b53f6edf68041a8e270a28031955 (diff)
downloadh99-897055910d8bda98b3454b6f66ad697edc4676b3.tar.gz
h99-897055910d8bda98b3454b6f66ad697edc4676b3.tar.bz2
h99-897055910d8bda98b3454b6f66ad697edc4676b3.zip
+57 +58
Diffstat (limited to 'H57.hs')
-rw-r--r--H57.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/H57.hs b/H57.hs
new file mode 100644
index 0000000..0af879f
--- /dev/null
+++ b/H57.hs
@@ -0,0 +1,11 @@
+import Tree
+
+construct :: Ord a => [a] -> Tree a
+construct = foldl add Empty
+
+add :: Ord a => Tree a -> a -> Tree a
+add Empty x = Branch x Empty Empty
+add t@(Branch a t1 t2) x = case compare x a of
+ LT -> Branch a (add t1 x) t2
+ GT -> Branch a t1 (add t2 x)
+ EQ -> t