Help the world stop coronavirus! Stay home!

Prev Next

Scala / Scala programs

Implement Selection sort program using Scala.

object SelectionSort {
  def main (args: Array[String]) {
    val myArray = Array(14,2,5,1,2,6)
    for (  i <- 0 to myArray.length-2)
    {
      var min =myArray(i)
      var pos = i
      for ( j <- i to myArray.length-1) 
         if (min> myArray(j)) 
           { min = myArray(j)
             pos = j
           }
      if (myArray(i) != min) {
        val temp =myArray(pos)
        myArray(pos) =myArray(i)
        myArray(i) = temp
        
      }
    }
    
    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