Advertisement
Guest User

Untitled

a guest
Dec 7th, 2014
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.39 KB | None | 0 0
  1. let most_frequent_elt list =
  2.   let rec loop maxelt maxcount elt count = function
  3.     | [] -> if count > maxcount then elt else maxelt
  4.     | x::xs ->
  5.         if elt = x then loop maxelt maxcount elt (count + 1) xs
  6.         else if count > maxcount then loop elt count x 1 xs
  7.         else loop maxelt maxcount x 1 xs in
  8.   match list with
  9.    | [] -> failwith "none"
  10.    | x::xs -> loop x 0 x 1 xs ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement