score:0

here's a fixed version that really does a bubblesort. i have no idea how you expected the other version to work, so this just does the obvious "compares each pair of adjacent items"

  implicit class arraywrappedswap[a](array: array[a]) {
    def swap(current: int, target: int): unit = {
      val tmp = array(target)
      array(target) = array(current)
      array(current) = tmp
    }
  }
  def bubblesort[a](arr: array[a])(implicit ordering: ordering[a]): array[a] = {
    var continuesort = true

    arr.indices.foreach(time => {

      if (!continuesort) {
        return arr

      } else {
        continuesort = false

        (time  until arr.length-1).foreach { index =>

          if (ordering.compare(arr(index), arr(index + 1)) > 0) {
            arr.swap(index, index+1)
            continuesort = true
          }

        }
      }
    })
    arr
  }                                               //> bubblesort: [a](arr: array[a])(implicit ordering: ordering[a])array[a]
  println(bubblesort(array(1, 3, 1, 2, 3)).mkstring(","))

Related Query

More Query from same tag