In: Computer Science
HELLO
I AM ADDING CODE HERE
PLEASE GO THROUGH IT
def isSorted[T](list: List[T])(implicit ord: Ordering[T]): Boolean = list match {
case Nil => true // an empty list is sorted
case x :: Nil => true // a single-element list is sorted
case x :: xs => ord.lteq(x, xs.head) && isSorted(xs) // if the first two elements are ordered and the rest are sorted, the full list is sorted too
}
val nums: List[Int] = List(1, 2, 3, 4, 5)
isSorted(nums)
OUTPUT