Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.21 KB | None | 0 0
  1. let rec extraireFeuille a l = match a,l with
  2.       |Vide,_ -> failwith "ERREUR : Arbre vide"
  3.       |Noeud(f1,f2),U::r  -> extraireFeuille f2 r
  4.       |Noeud(f1,f2),Z::r -> extraireFeuille f1 []
  5.       |Noeud(_,_),[] -> failwith "1ERREUR : Feuille introuvable dans l'arbre."
  6.       |Feuille(c1),U::[] -> c1
  7.       |Feuille(c1),Z::[] -> c1
  8.       |Feuille(c1),[] -> c1;;
  9.  
  10.   let rec decodage a l_bin = match a,l_bin with
  11.     |Vide,_  -> failwith "ERREUR : Arbre vide avec liste pleine."
  12.     |Noeud(_,_),[]  -> failwith "ERREUR : Arbre plein avec liste vide."
  13.     |Feuille(_),[]    -> failwith "ERREUR : Arbre plein avec liste vide"
  14.     |Feuille(_),U::[] -> "" ^ (Char.escaped (extraireFeuille a [U]))
  15.     |Feuille(_),U::r ->  "" ^ (Char.escaped (extraireFeuille a [U])) ^ decodage a r
  16.     |Feuille(_),Z::_ -> failwith "ERREUR : Liste incorrecte"
  17.     |Noeud(_,_),_::_-> let rec loopInList a' l' t' s' =
  18.       match l' with
  19.         |c::[] when c = U -> let s' = (s' ^ Char.escaped(extraireFeuille a' (t'@[c]))) in s'
  20.         |c::r when c = U -> loopInList a' r (t'@[c]) s'
  21.         |c::r when c = Z -> let s' = (s' ^ Char.escaped(extraireFeuille a' (t'@[c]))) in (loopInList a' r [] s')
  22.         |[] -> s'
  23.       in loopInList a l_bin [] "";;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement