Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let creer x = (
- let tree = vide() in
- let currentTree = tree in
- List.iter(fun item ->
- for i = 0 to (String.length item) - 1 do
- let letter = (String.get item i) in
- let Noeud(_, childs) = currentTree in
- let letterFoundInChilds = false in
- let rec check_if_letter_exists c = match c with
- | [] -> ()
- | current::next -> (
- let (childLetter, childTree) = current in
- if childLetter = letter then (
- letterFoundInChilds = true;
- currentTree = childTree;
- ();
- ) else check_if_letter_exists next;
- ) in check_if_letter_exists !childs;
- if letterFoundInChilds = false then (
- let isLastLetter = (i = (String.length item) - 1);
- let newTree = (letter, Noeud(ref isLastLetter, ref []));
- !childs @ [newTree];
- ) in
- print_endline (String.make 1 letter);
- done
- ) listeMots
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement