Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open W3q6h
- (*lfreq_: value, list, freqCounter*)
- let rec lfreq_ x l n = match l with
- | hd::tl ->
- if hd = x then
- lfreq_ x tl n+1
- else
- lfreq_ x tl n
- | _ -> n
- (*lfreq: value, list*)
- let lfreq x l = lfreq_ x l 0
- (*delete_: value, inList, outList*)
- let rec delete_ x li lo = match li with
- | hd::tl ->
- if hd != x then
- delete_ x tl (hd::lo)
- else
- delete_ x tl lo
- | _ -> lo (*removed reverse - not needed here*)
- (*delete: value, list*)
- let delete x l = delete_ x l []
- (*freq_: list, element, elementFreq*)
- let rec freq_ l e ef = match l with
- | hd::tl ->
- let cef = lfreq hd l in
- if cef > ef then
- freq_ (delete hd l) hd cef
- else
- freq_ (delete hd l) e ef
- | _ -> e
- (*freq: list*)
- (*Returns the most frequent element in the list*)
- let freq l = freq_ l 0 0
- let _ = test freq
Add Comment
Please, Sign In to add comment