Return to Snippet

Revision: 38081
at December 24, 2010 14:39 by openote


Initial Code
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

Initial URL


Initial Description
The items commented out were the way that things would have had to been coded if there was no 
    sort! 
function in ruby

Initial Title
Sorting in Ruby

Initial Tags


Initial Language
Ruby