Last active
September 11, 2017 19:01
-
-
Save Nitesh-Mishra/b159b5aebac96e17570f1d61926e4e06 to your computer and use it in GitHub Desktop.
Bubble Sort program 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
| # 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