diff options
[FP/P12] Added partial start to first exercise
1 files changed, 19 insertions, 0 deletions
| -rw-r--r-- | Year 2/Functional Programming/12-Practice-05.01.2023.hs | 19 |
diff --git a/Year 2/Functional Programming/12-Practice-05.01.2023.hs b/Year 2/Functional Programming/12-Practice-05.01.2023.hs new file mode 100644 index 0000000..93db0e5 --- /dev/null +++ b/Year 2/Functional Programming/12-Practice-05.01.2023.hs @@ -0,0 +1,19 @@ +-- Ex1 +data BTree a = Nil | Node a (BTree a) (BTree a) + deriving (Eq,Show,Read) + +size :: BTree a -> Int +size Nil = 0 +size (Node n bt1 bt2) = 1 + size bt1 + size bt2 + +height :: BTree a -> Int +height Nil = 0 +height (Node n bt1 bt2) = 1 + max (height bt1) (height bt2) + +sumTree :: BTree Int -> Int +sumTree Nil = 0 +sumTree (Node n bt1 bt2) = n + sumTree bt1 + sumTree bt2 + +main :: IO() +main = do + print("Hello World") |
