Advertisement
Guest User

Untitled

a guest
Nov 5th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.72 KB | None | 0 0
  1. (* b *)
  2.  
  3. let czyIstniejeFL f xs = List.fold_left (fun x y -> if f y then x || true else x || false) false xs;;
  4.  
  5. (* c *)
  6.  
  7. let czyIstniejeFR f xs = List.fold_right (fun x y -> if f x then true || y else false || y) xs false;;
  8.  
  9. (*Zadanie 4*)
  10. let rec merge l x y = match (x,y) with
  11.     | ([],_) -> y
  12.     | (_,[]) -> x
  13.     | (h1::t1, h2::t2) ->
  14.     if l h1 h2
  15.         then h1::(merge l t1 y)
  16.         else h2::(merge l x t2);;
  17.  
  18. let rec split x y z = match x with
  19.      | [] -> (y,z)
  20.      | x::xs -> split xs z (x::y);;
  21.  
  22. let rec mergesort l x = match x with
  23.     | ([] | _::[]) -> x
  24.     | _ -> let (pri,seg) = split x [] []
  25.            in merge l (mergesort l pri) (mergesort l seg);;
  26.  
  27. mergesort (>) [2;6;1;8];;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement