Last active
December 18, 2015 22:29
-
-
Save bernEsp/5855008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers = 100000.times.map { Random.rand(2000) } | |
t = Time.now | |
yield | |
ruby_sort = numbers.sort | |
p "it tooks #{t-Time.now}s" | |
#[5, -3, 3, 20, -50, 1, -1, 2] | |
def bubblesort( collection ) | |
t = Time.now | |
for i in 0..collection.length-1 | |
collection.each_with_index do |item, index| | |
break if collection[index + 1].nil? | |
if item > collection[index + 1] | |
collection[index] = collection[index + 1] | |
collection[index + 1] = item | |
end | |
end | |
end | |
puts "tooks #{t-Time.now}s" | |
collection | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment