Created
September 20, 2012 18:09
-
-
Save nsfyn55/3757441 to your computer and use it in GitHub Desktop.
Bubble Sort
This file contains hidden or 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 App{ | |
def main(args: Array[String]){ | |
println(sort(List(6,1,56,3,5,4,9))) | |
} | |
def sort(xs:List[Int]):List[Int] = { | |
def innerSort(xs: List[Int], count:Int): List[Int] = count match { | |
case 0 => xs | |
case _ => innerSort(pass(xs), count-1) | |
} | |
innerSort(xs, xs.length) | |
} | |
def pass(xs:List[Int]):List[Int] = xs match { | |
case Nil => Nil | |
case x::Nil => x::Nil | |
case l::r::xs if(l>r) => r::pass(l::xs) | |
case l::r::xs => l::pass(r::xs) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment