Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/P06/alimento_concreto.rb

Overview

Aqui abro la clase array y creo los metodos de ordenacion for y each. El sort ya lo tiene la clase

Instance Method Summary collapse

Instance Method Details

#ordenar_eachObject

Este es el metodo de ordenacion each.



55
56
57
58
59
60
61
62
63
# File 'lib/P06/alimento_concreto.rb', line 55

def ordenar_each
    
    @ordenado= []
    aux_self=self.clone
    
    (0..self.size-1).each{|i| min=aux_self.min; @ordenado << min; aux_self.delete(min)}
    
    @ordenado
end

#ordenar_forObject

Este es el metodo de ordenacio for. Utilizo el metodo burbuja.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/P06/alimento_concreto.rb', line 38

def ordenar_for
    
    @vector=self
    
    for i in (0..@vector.size-1)
        for j in (0..@vector.size-1)
            if j+1 != @vector.size
                if @vector[j+1] < @vector[j]
                    @vector[j], @vector[j+1] = @vector[j+1], @vector[j]
                end
            end
        end
    end
    @vector
end