added ruby bubble_sort example (#33907)
* added ruby bubble_sort example * fix: corrected code block syntax * fix: fixed typo and used 2 space indentation
This commit is contained in:
committed by
Randell Dawson
parent
5c51c407c0
commit
3e175e52b3
@ -51,7 +51,6 @@ Now, the array is already sorted, but our algorithm does not know if it is compl
|
|||||||
### Video Explanation
|
### Video Explanation
|
||||||
[Bubble sort in easy way](https://www.youtube.com/watch?v=Jdtq5uKz-w4)
|
[Bubble sort in easy way](https://www.youtube.com/watch?v=Jdtq5uKz-w4)
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
### Example in JavaScript
|
### Example in JavaScript
|
||||||
```js
|
```js
|
||||||
@ -159,6 +158,22 @@ def bubbleSort(arr):
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Example in Ruby
|
||||||
|
```ruby
|
||||||
|
def bubble_sort(arr)
|
||||||
|
sorted = false
|
||||||
|
until sorted
|
||||||
|
sorted = true
|
||||||
|
(arr.count-1).times do|i|
|
||||||
|
if arr[i] > arr[i + 1]
|
||||||
|
arr[i], arr[i +1] = arr[i +1], arr[i]
|
||||||
|
sorted = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
arr end
|
||||||
|
```
|
||||||
|
|
||||||
### Example in PHP
|
### Example in PHP
|
||||||
```php
|
```php
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user