Created
March 15, 2013 16:02
-
-
Save Wizmann/5170965 to your computer and use it in GitHub Desktop.
归并排序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//归并排序 | |
object MergeSort | |
{ | |
def main(args:Array[String]) { | |
val a = readLine split(" ") map(_ toInt) toList | |
val b = readLine split(" ") map(_ toInt) toList | |
def merge_sort(a : List[Int], b: List[Int]): List[Int] = { | |
a match { | |
case Nil => b | |
case _ => b match | |
{ | |
case Nil => a | |
case x::xs => | |
{ | |
if(x<a.head) | |
x :: merge_sort(a,xs) | |
else | |
a.head :: merge_sort(a tail, b) | |
} | |
} | |
} | |
} | |
println(merge_sort(a,b).mkString(" ")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment