Advertisement
Guest User

lista4p1

a guest
Nov 21st, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (* Igor Malgrab *)
  2.  
  3. (* zadanie 2 *)
  4.  
  5. type 'a bt = Empty | Node of 'a * 'a bt * 'a bt;;
  6.  
  7. let rec foldBT f acc bt =
  8.   match bt with
  9.     Empty -> acc
  10.   | Node(v, l, r) -> foldBT f (f v ((foldBT f acc r), acc)) l;;
  11.  
  12. (* zadanie 3 *)
  13.  
  14. let sumBTfold = function t -> foldBT (fun nval (racc, acc) -> nval + racc) 0  t;;
  15.  
  16. sumBTfold (Node(1, Empty, Node(2, Empty, Node(3, Empty, Node(4, Empty, Empty)))));;
  17.  
  18. let inorderBTfold = 0;;
  19.  
  20. (* zadanie 4 *)
  21.  
  22.  
  23. (* zadanie 5 *)
  24.  
  25. type 'a tree = L of 'a | N of 'a tree * 'a tree;;
  26.  
  27. let store t =
  28.   let rec aux = function
  29.       (L(x), xs) -> Some x::xs
  30.     | (N(l, r), xs) -> aux(l, aux(r, None::xs))
  31.   in aux (t, []);;
  32.  
  33. let drzewo1 = N(L(1), N(L(2), L(3)));;
  34.  
  35. store drzewo1;;
  36.  
  37. store Empty;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement