Created
November 6, 2019 01:57
-
-
Save san9dev/dfaa4ce579d60470a7fbfc65f7069d98 to your computer and use it in GitHub Desktop.
bubule sort with ruby
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
# buble sort with ruby | |
def bublesort(arr) | |
n = arr.length - 1 | |
sorted = true | |
while sorted do | |
sorted = false | |
n.times do |i| | |
if arr[i] > arr[i + 1] | |
arr[i], arr[i + 1] = arr[i + 1], arr[i] # exchange array elements | |
sorted = true | |
end | |
end | |
end | |
arr | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment