Questions / réponses

parameters

parameters

Napisane przez: Maxime Denis ( )
Liczba odpowiedzi: 1

Bonjour, je ne comprends pas d’où viens mon erreur pour la fonction parameters,

Échec sur les arguments suivants:
Empty

voici mon code:



let rec height t =
  match t with
    Empty -> (-1)
  |Bin (x,g,d) ->  1+max(height g) ( height d)
 
let arity t=
  match t with
    Empty->(-1)
   |Bin(x,g,d)->match (g,d) with
                  (Empty,Empty)->0
                 |(Empty,_)->1
                 |(_,Empty)->1
                 |(_,_)->2

let rec arity2 t =
    match t with
    Empty -> 0
    | Bin(x,left,right) -> if arity t = 2
                            then 1 + arity2 left + arity2 right
                            else 0 + arity2 left  + arity2 right
 
   
let rec arity1 t =
    match t with
    Empty -> 0
    | Bin(x,left,right) -> if arity t = 1
                            then 1 + arity1 left + arity1 right
                            else 0 + arity1 left  + arity1 right
 
let rec size tree =
  match tree with
    Empty -> 1
   |Bin(x,left,right)->1+(size left) + (size right)
  
let rec internal t =
   match t with
   Empty -> 0
   |Bin(x,left,right) -> 1+ internal left + internal right


let  nb_leaves t = size t - internal t

let parameters t = match t with
    Empty->(size t,nb_leaves t,arity1 t,arity2 t,0)
  |_->(size t,nb_leaves t,arity1 t,arity2 t,height t)
 

Merci.

W odpowiedzi na Maxime Denis

Re: parameters

Napisane przez: Simon Archipoff ( )

Il y a plusieurs problème, mais celui qui est posé pour l'arbre vide (Empty) c'est que sa taille n'est pas de 1, mais de 0.

Une fois ce problème corrigé, vous verez que la fonction internal mesure exactement la même chose que size. Les nœuds internes sont ceux qui ne sont pas des feuilles, autrement dit, ceux qui ont au moins un fils.