Skip to content

Instantly share code, notes, and snippets.

@Nitesh-Mishra
Last active September 11, 2017 19:01
Show Gist options
  • Select an option

  • Save Nitesh-Mishra/b159b5aebac96e17570f1d61926e4e06 to your computer and use it in GitHub Desktop.

Select an option

Save Nitesh-Mishra/b159b5aebac96e17570f1d61926e4e06 to your computer and use it in GitHub Desktop.
Bubble Sort program in ruby
# bubble_sort.rb
#
# $ ruby bubble_sort.rb
# [1, 2, 3, 4, 5, 6, 7, 8]
def bubble_sort(array)
for i in 0..array.length - 1
for j in 0..array.length - 2
if array[j] > array[j+1]
array[j],array[j+1] = array[j+1],array[j]
end
end
end
end
array = [6,5,3,1,8,7,2,4]
bubble_sort array
print array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment