sort numbers by

number = gets.to_i

numbers = gets.split.map(&:to_i)

for n in (0..number - 1) do
  min_index = n
  for m in (n..number - 1) do
    if numbers[m] < numbers[min_index]
      x = numbers[m]
      numbers[m] = numbers[min_index]
      numbers[min_index] = x
    end
  end
end
puts numbers.join(" ")

# abc = ["a","b","c"]
# x = abc[1]
# abc[1] = abc[2]
# abc[2] = x
# puts abc

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page