Last active
February 27, 2017 22:20
-
-
Save blackknight36/5ffab9f18d96ff17097dcbe0387262f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
def print_arr(ar) | |
ar.each do |i| | |
printf("%d ", i) | |
end | |
puts | |
end | |
def bubble_sort(a) | |
n = a.length | |
for k in 1..n-1 | |
for i in 0..n-k-1 | |
if a[i] > a[i+1] then | |
a[i], a[i+1] = a[i+1], a[i] | |
end | |
i += 1 | |
end | |
end | |
return a | |
end | |
ar = Array.new(100) { rand(1...1000) } | |
print_arr(bubble_sort(ar)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment