Sha256: f517729be1f95b62f04143d90af142f6252d0b884a84c2329a9acc8a527ec5cc

Contents?: true

Size: 504 Bytes

Versions: 2

Compression:

Stored size: 504 Bytes

Contents

module Sortviz
  # selection_sort is brought in from
  # https://coderwall.com/p/z8vowg/simple-sorting-algorithms-with-ruby
  def selectionsort(list)
    (0...list.size).each do |j|
      # find index of minimum element in the unsorted part 
      iMin = j
      (j+1...list.size).each do |i|
        iMin = i if list[i] < list[iMin]
      end

      # then swap it
      list[j], list[iMin] = list[iMin], list[j]
      yield list, j
    end
  end

  define_algorithm "Selection Sort", :selectionsort
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sortviz-0.6.1 lib/algorithms/selectionsort.rb
sortviz-0.6.0 lib/algorithms/selectionsort.rb