Last active
April 29, 2017 13:44
-
-
Save trkrameshkumar/035c043977f098580fdcdd82d969e329 to your computer and use it in GitHub Desktop.
Bubble sort in Ruby
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
def bubble_sort array | |
(array.length-1).times do |i| | |
(array.length-1-i).times do |j| | |
if array[j] > array[j+1] | |
array[j], array[j+1]=array[j+1], array[j] | |
end | |
end | |
end | |
array | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment