Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.85 KB | None | 0 0
  1. let creer x = (
  2.     let tree = vide() in
  3.     let currentTree = tree in
  4.         List.iter(fun item ->
  5.             for i = 0 to (String.length item) - 1 do
  6.                 let letter =  (String.get item i) in
  7.                 let Noeud(_, childs) = currentTree in
  8.                 let letterFoundInChilds = false in
  9.                 let rec check_if_letter_exists c = match c with
  10.                 | [] -> ()
  11.                 | current::next -> (
  12.                     let (childLetter, childTree) = current in
  13.                     if childLetter = letter then (
  14.                         letterFoundInChilds = true;
  15.                         currentTree = childTree;
  16.                         ();
  17.                     ) else check_if_letter_exists next;
  18.                 ) in check_if_letter_exists !childs;
  19.                 if letterFoundInChilds = false then (
  20.                     let isLastLetter = (i = (String.length item) - 1);
  21.                     let newTree = (letter, Noeud(ref isLastLetter, ref []));
  22.                     !childs @ [newTree];
  23.                 ) in
  24.                 print_endline (String.make 1 letter);
  25.             done   
  26.         ) listeMots
  27. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement