Created
January 25, 2018 21:08
-
-
Save arnaudoff/915b1100901344ca22ad0997b175b123 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 BubbleSort { | |
def sort(xs: List[Int]) = { | |
def bsort(xs: List[Int], current: Int, dest: Int): List[Int] = { | |
dest match { | |
case 0 => xs | |
case _ if (dest == current) => bsort(xs, 0, dest - 1) | |
case _ => | |
if (xs(current) > xs(current + 1)) { | |
var tmp = xs(current + 1) | |
xs(current + 1) = xs(current) | |
xs(current) = tmp | |
} | |
bsort(xs, current + 1, dest) | |
} | |
} | |
bsort(xs, 0, xs.length - 1) | |
} | |
} |
PlamenNeshkov
commented
Jan 25, 2018
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment