diff options
| Commit | 40ffc86693349399c013de477a9e0341238c4129 (patch) | |
|---|---|---|
| Author | 2023-01-05 13:53:52 +0200 | |
| Committer | 2023-01-05 13:53:52 +0200 | |
| Files | ff004cf6ee118ddfb77c4d80dd04b62ea989880a | |
| uni-projects-40ffc86693349399c013de477a9e0341238c4129.tar uni-projects-40ffc86693349399c013de477a9e0341238c4129.tar.gz uni-projects-40ffc86693349399c013de477a9e0341238c4129.zip | ||
| Parent | 0415852b08e994648c44510a510a5fca0681c5b5 (diff) | |
[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") |
