Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val toBeSorted = Array(9,-1,7,5,4)
- def bubbleSort(array: Array[Int]) = {
- println(array.mkString("[", ", ", "]"))
- for (i <- array.indices) {
- for (j <- 1 until array.length - i) {
- if (array(j - 1) > array(j)) {
- val temp = array(j - 1)
- array(j - 1) = array(j)
- array(j) = temp
- println(array.mkString("[", ", ", "]"))
- }
- }
- }
- array
- }
- bubbleSort(toBeSorted)
Add Comment
Please, Sign In to add comment