Guest User

Untitled

a guest
May 20th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --58. Ackermannfunktion (10 Punkte)
  2. af 0 n=n+1
  3. af m 0=2
  4. af m n=af (m-1) (af m (n-1))
  5.  
  6. a 0 n= 2*n
  7. a m 0=2
  8. a m n=a (m-1) (a m (n-1))
  9. {-
  10. B1(n)=n+1
  11. B2(n)=n+2
  12. B3(n)=2^(2+n) -2
  13. -}
  14.  
  15. --60. Wörterbuchoperationen Implementierung durch algebraischen Datentyp
  16. data Wbuch a b =
  17.    Einf (Wbuch a b) a b |
  18.    Leer
  19.    deriving Show
  20.  
  21. exa= Einf (Einf (Einf (Einf (Leer)  6 "Asaf") 5 "Kai") 3 "Chris") 1 "Jakob"
  22. exb= Einf (Einf (Einf (Einf (Leer)  12 "Sebastian") 9 "VMax") 8 "Ani") 4 "Mi"
  23.  
  24. janzahl:: Wbuch a b -> Int
  25. janzahl Leer=0
  26. janzahl (Einf n a b)= 1+ (janzahl n)
  27.  
  28. --61. Datenstruktur
  29. jdele Leer _= Leer
  30. jdele (Einf n a b) x
  31.     | x==a =jdele n x
  32.     | otherwise =Einf (jdele n x) a b
  33.  
  34. --62. Vereinigung von Wörterbüchern
  35. jmerge Leer Leer= Leer
  36. jmerge Leer y = y
  37. jmerge x Leer = x
  38. jmerge (Einf n a b) (Einf m c d)
  39.     |a<=c =Einf (jmerge n (Einf m c d)) a b
  40.     |otherwise = Einf (jmerge (Einf n a b) m) c d
  41. --63. Bäume
  42.  
  43. data (Ord a) => Suchbaum a b =
  44.     Knoten a b (Suchbaum a b) (Suchbaum a b)
  45.     | Nil
  46.     deriving Show
  47. exc = Knoten 8 "Chris" (Knoten 5 "Jakob" (Knoten 4 "Mia" (Nil) (Nil)) (Knoten 6 "Ilse" (Nil) (Nil)) ) (Knoten 9 "Kai" (Nil) (Nil))
  48.  
  49. --jdeepTree::
  50. jdeepTree t=maximum (jdeepTree' t 0)
  51.             where
  52.             jdeepTree' Nil _ = [-1]
  53.             jdeepTree' (Knoten a b x y) i= [i]++jdeepTree' x (i+1) ++ jdeepTree' y (i+1)
  54.  
  55. -- 64. Bäume
  56. data BBaum a = BLeer | BKnoten a (BBaum a) (BBaum a)
  57.     deriving Show
  58. exd= BKnoten 7 (BKnoten 2 (BKnoten 9 (BLeer)(BLeer)) (BLeer)) (BKnoten 3 (BLeer) (BLeer))
  59. jconvToDeepTree Nil _= BLeer
  60. jconvToDeepTree (Knoten a b x y) i= BKnoten i (jconvToDeepTree x (i+1)) (jconvToDeepTree y (i+1))
  61.  
  62. -- Graveyard
  63. jfind:: Eq a => Wbuch a b -> a -> Maybe b
  64. jfind Leer _ = Nothing
  65. jfind (Einf n a b) x
  66.     |x==a =Just b
  67.     |otherwise =jfind n x
  68.    
  69. jadd Leer a b =Einf Leer a b
  70. jadd (Einf n a b) v c
  71.     |v <= a = Einf (Einf n a b) v c
  72.     |otherwise =Einf (jadd n v c) a b
Add Comment
Please, Sign In to add comment