Skip to content

Commit a5114c8

Browse files
authored
Create bubble_sort.rb
1 parent 6ac0768 commit a5114c8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def bubble_sort array
2+
is_sorted = false
3+
digits = (0..array.length - 2)
4+
5+
until is_sorted
6+
is_sorted = true
7+
digits.each do |i|
8+
if array[i] > array[i+1]
9+
array[i], array[i+1] = array[i+1], array[i]
10+
is_sorted = false
11+
end
12+
end
13+
end
14+
print array
15+
end
16+
17+
# Check the result
18+
bubble_sort([2,41,61,0,1,24,124])

0 commit comments

Comments
 (0)