Help the world stop coronavirus! Stay home!

Prev Next

Scala / Scala programs

Implement bubble sort using Scala.

object BubbleSort {
  def main(args: Array[String]) {
    val myArray = Array(18, 2, 5, 1, 63, 17)
    var unsorted_last_index = myArray.length - 2;

    while (unsorted_last_index > 0) {
      for (j <- 0 to unsorted_last_index)
        if (myArray(j) > myArray(j + 1)) {
          val temp = myArray(j)
          myArray(j) = myArray(j + 1)
          myArray(j + 1) = temp
        }
      unsorted_last_index = unsorted_last_index - 1;
    }

    println(myArray deep)
  }
}

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...


Comments & Discussions