Tag: bubble

Insertion Sort in Scala-This is coding algorithm

object Sort{ def insertionSort () : Unit = { var myArray = Array(4, 7, 8, 3, 1, 9, 2, 5, 0, 6) var buf:Int = 0; for(i <- 1 to (myArray.length)) { buf = myArray(i) var j = i-1 while ( myArray(j) > buf && j >= 0){ myArray(j+1) = myArray(j) j = j - … Continue reading Insertion Sort in Scala-This is coding algorithm

Advertisements

bubble sort scala

/** blue sort*/ def Bluesort(array : Array[Int]): Array[Int] = { var flag = false for(i<- 0 until array.length -1) if(array(i+1) > array(i)){ //tang dan,giam dan > val tmp = array(i) array(i) = array(i+1) array(i+1) = tmp flag = true } // Repeat until we don't have anymore swaps if(flag) Bluesort(array) else array } def main(args: … Continue reading bubble sort scala