I\'m trying to write a function which will recursively find the largest element in a list of integers. I know how to do this in Java, but can\'t understand how to do this at Sca
I presume this is for the progfun-example
This is the simplest recursive solution I could come up with
def max(xs: List[Int]): Int = {
if (xs.isEmpty) throw new NoSuchElementException("The list is empty")
val tail = xs.tail
if (!tail.isEmpty) maxOfTwo(xs.head, max(xs.tail))
else xs.head
}
def maxOfTwo(x: Int, y: Int): Int = {
if (x >= y) x
else y
}