Skip to content

Instantly share code, notes, and snippets.

@karimamer
Created May 5, 2013 23:18
Show Gist options
  • Save karimamer/5522555 to your computer and use it in GitHub Desktop.
Save karimamer/5522555 to your computer and use it in GitHub Desktop.
def MSort(k:List[Int]): List[Int]={
val x = k.length / 2
if (x == 0) k
else {
def merge( k:List[Int], o:List[Int]):List[Int] = (k ,o) match {
case (Nil , o ) => o
case(k , Nil) => k
case(n ::ks , y :: os) => if (x > y) n :: merge(k ,os) else y :: merge(o,ks)
}
val (mka , kka) = k splitAt x
merge(MSort(mka),MSort(kka))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment