Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Last active February 27, 2017 22:20
Show Gist options
  • Save blackknight36/5ffab9f18d96ff17097dcbe0387262f8 to your computer and use it in GitHub Desktop.
Save blackknight36/5ffab9f18d96ff17097dcbe0387262f8 to your computer and use it in GitHub Desktop.
#!/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