/ Published in: Ruby

The items commented out were the way that things would have had to been coded if there was no
sort!
function in ruby
sort!
function in ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class Inputstuff def initialize @a = 0 @array = Array.new @counter = 0 end def receive @a = gets @a = @a.to_i while @a >= 0 do @array << @a @counter += 1 @a = gets @a = @a.to_i end end def sort # 0.upto(@counter-2) do |coolstuff| # if @array[coolstuff] > @array[coolstuff+1] # @array[coolstuff], @array[coolstuff+1] = @array[coolstuff+1], @array[coolstuff] # end # @array.reverse # end @array.sort! {|x,y| y <=> x} end def results @counter.times do |coolerstuff| puts @array[coolerstuff] end end end i = Inputstuff.new i.receive i.sort i.results
Comments
