Guest User

Untitled

a guest
Jan 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. val toBeSorted = Array(9,-1,7,5,4)
  2.  
  3. def bubbleSort(array: Array[Int]) = {
  4. println(array.mkString("[", ", ", "]"))
  5. for (i <- array.indices) {
  6. for (j <- 1 until array.length - i) {
  7. if (array(j - 1) > array(j)) {
  8. val temp = array(j - 1)
  9. array(j - 1) = array(j)
  10. array(j) = temp
  11. println(array.mkString("[", ", ", "]"))
  12. }
  13. }
  14. }
  15. array
  16. }
  17.  
  18. bubbleSort(toBeSorted)
Add Comment
Please, Sign In to add comment