Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Somme des éléments d'une liste
- def sum(xs: List[Int]): Int = {
- xs.size match {
- case 0 => 0
- case 1 => xs.head
- case _ => xs.head + sum(xs.tail)
- }
- }
- // Element maximum d'une liste :
- def max(xs: List[Int]): Int = {
- xs.size match {
- case 0 => throw new java.util.NoSuchElementException("C'est tout vide !");
- case 1 => xs.head
- case _ =>
- if ( xs.head > max(xs.tail) )
- return xs.head
- else
- return max(xs.tail)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement