Решенеия на задачите от упражненията

Решения на задачите от 17.01.2007

Re: Решения на задачите от 17.01.2007

от Климентина Русева -
Number of replies: 0

data BinTree a = Empty | Node a (BinTree a) (BinTree a)
               deriving (Show,Eq)
 
{-
insertBot :: BinTree -> Int -> BinTree (former definitoin)
insertBot :: BinTree Int -> Int -> BinTree Int
insertBot :: BinTree String -> String -> BinTree String
 -}

t = Node (10,100)(Node (10,50) Empty (Node (10,60) Empty Empty))(Node (5,102) (Node (7,102) Empty Empty) Empty)
 
isElem x Empty = False
isElem x (Node v l r)
 |x<(fst v) || x>(snd v) = isElem x r
 |x>=(fst v) && x<=(snd v) = True

d = Node ("hello")(Node ("cat") Empty (Node ("dog") Empty Empty))(Node ("world") (Node ("pig") Empty Empty) Empty)

-- foldr (+) 0 (map (\c-> if c==x then 1 else 0) s) --

howMany x "" = 0
howMany x (h:t)
 |x==h  = 1+ howMany x t
 |otherwise = howMany x t
 
countS Empty x = 0
countS (Node v l r) x = (howMany x v) + (countS l x) + (countS r x)