Quick sort in Scala
11Nov09
def qsort(list:List[Int]):List[Int] =
{
list match {
case x::xs => qsort(xs filter(_<x) ) ::: x :: qsort(xs filter(_>x))
case Nil => Nil
}
}
print(qsort(List(4,6,5,0,2,3,1,7,8,9)))
Short and sweet!…
Filed under: Uncategorized | Leave a Comment
No Responses Yet to “Quick sort in Scala”