Código Ruby – Ordenamiento por Selección

El código realiza un Ordenamiento de datos numéricos haciendo uso del Método de Selección en Ruby:

def seleccion_sort(arr)
  n = arr.length
  for i in 0..n-2
    min_index = i
    for j in i+1..n-1
      if arr[min_index] > arr[j]
        min_index = j
      end
    end
    arr[i], arr[min_index] = arr[min_index], arr[i]
  end
end

arr = [64, 34, 25, 12, 22, 11, 90]
seleccion_sort(arr)
puts "Arreglo ordenado: #{arr}"

2 thoughts on “Código Ruby – Ordenamiento por Selección

  1. Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

Deja un comentario