13 lines
305 B
Scala
13 lines
305 B
Scala
def merge(x: List[Int], y: List[Int]): List[Int] = {
|
|
(x, y) match {
|
|
case (list, Nil) => list
|
|
case (Nil, list) => list
|
|
case (e1::rest1, e2::rest2) =>
|
|
if (e1 < e2) e1::merge(rest1, y)
|
|
else e2::merge(x, rest2)
|
|
}
|
|
}
|
|
|
|
val n1 = List(0, 2, 4, 6)
|
|
val n2 = List(1, 3, 5, 7)
|
|
merge(n1, n2) |