Class: SelectionSort

Inherits:
Object
  • Object
show all
Defined in:
lib/brutish_sorts/selection_sort.rb

Class Method Summary collapse

Class Method Details

.min_index(array, start_index) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/brutish_sorts/selection_sort.rb', line 10

def self.min_index(array, start_index)
  min_value = array[start_index]
  min_index = start_index
  si_1 = start_index + 1

  for a in si_1..array.length - 1
    if array[a] < min_value
      min_index = a
      min_value = array[a]
    end
  end
  min_index
end

.swap(array, pivot, index) ⇒ Object



3
4
5
6
7
8
# File 'lib/brutish_sorts/selection_sort.rb', line 3

def self.swap(array, pivot, index)
  temp = array[pivot]
  array[pivot] = array[index]
  array[index] = temp
  array
end