Skip to content

Instantly share code, notes, and snippets.

@daiksy
Last active January 2, 2016 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daiksy/8241124 to your computer and use it in GitHub Desktop.
Save daiksy/8241124 to your computer and use it in GitHub Desktop.
def bubbleSort(arr: Array[Int]): Array[Int] = {
for(i <- 0 until arr.length - 1; j <- 0 until arr.length - 1 - i) {
if (arr(j) > arr (j + 1)) {
val temp = arr(j)
arr(j) = arr(j + 1)
arr(j + 1) = temp
}
}
arr
}
bubbleSort(Array(5,3,2,6,1,8)) foreach println
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment