Jump to content

Sorting algorithms/Bubble sort: Difference between revisions

+python
m (Added Sorting Algorithm template)
(+python)
Line 178:
puts ary.sort!
# => [3, 4, 6, 6, 8, 23, 78]
 
==[[Python]]==
 
def bubblesort(x):
for i in range(len(x) - 2):
for j in range(i, len(x) - 1):
if x[j] > x[j+1]:
x[j], x[j+1] = x[j+1], x[j]
return x
x = [3, 78, 4, 23, 6, 8, 6]
bubblesort(x) # [3, 4, 6, 6, 8, 23, 78]
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.