Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
m (Added Sorting Algorithm template) |
(+python) |
||
Line 178: | Line 178: | ||
puts ary.sort! |
puts ary.sort! |
||
# => [3, 4, 6, 6, 8, 23, 78] |
# => [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] |