Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/alimento/array.rb

Instance Method Summary collapse

Instance Method Details

#nSortObject



16
17
18
# File 'lib/alimento/array.rb', line 16

def nSort
  self.sort
end


5
6
7
8
9
# File 'lib/alimento/array.rb', line 5

def print
  puts "["
  self.each {|x| puts x}
  puts "]"
end

#sortEachObject



11
12
13
14
# File 'lib/alimento/array.rb', line 11

def sortEach
  v = self
  v.each { min = v.min;  return rest = v.select {|x| x == min} + v.select{ |x| x > min}.sortEach;  }
end

#sortForObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/alimento/array.rb', line 20

def sortFor
  v = self
  for i in (0..v.size-1).to_a do
    min = i
    for j in (i..v.size-1).to_a do
      if v[j] < v[min]
        min = j
      end
    end
    v[i],v[min] = v[min],v[i]
  end
  v
end