Q6: supprimer_element

Profil

supprimer_element: typelt x liste -> liste

Exemples

supprimer_element(a, (a b a a c a)) = (b c)
supprimer_element( a, ()) = ()
supprimer_element( a, (a)) = ()
supprimer_element( a, (b)) = (b) = cons(b, ()) = cons(b, supprimer_element(a, ()))
supprimer_element( a, (a b)) = (b) = supprimer_element(a, (b)) = supprimer_element(a, reste( (a b) ))
supprimer_element( a, (b a)) = (b) 
  = cons(b, supprimer_element(a, (a))) 
  = cons(b, supprimer_element(a, reste(b a)))
supprimer_element( a, (a b a a c a)) 
 =  supprimer_element(a, (b a a c a)) 
 =  cons(b, supprimer_element(a, (a a c a) )) 
 =  cons(b, supprimer_element(a, (a c a) )) 
 =  cons(b, supprimer_element(a, (c a) )) 
 =  cons(b, cons(c, supprimer_element(a, (a) ))) 
 =  cons(b, cons(c, supprimer_element(a, () )))
 =  cons(b, cons(c, () ))
 =  ( b c ) 

Axiomes

supprimer_element(x, liste_vide()) =  liste_vide()
supprimer_element(x, cons(y,L)) = si_alors_si_finsi(x=y, supprimer_element(x, L), cons(y, supprimer_element(x, L)))

Traduction en C

liste supprimer_element(TYPEELT val, liste L)
{
  if (est_vide(L))
  {
    return liste_vide();
  }
  else
  {
    if (prem(L) == val)
    {
      return supprimer_element(val, reste(L));
    }
    else
    {
      return cons(prem(L), supprimer_element(val, reste(L)));
    }
  }
}