+ 1

How to write a simple code on bubble sort in Python.

1st Sep 2018, 6:49 AM
Naveen
Naveen - avatar
3 ответов
1st Sep 2018, 6:51 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 3
def bubble_sort(nlist): for passnum in range(len(nlist)-1,0,-1): for j in range(passnum): if nlist[j]>nlist[j+1]: nlist[j], nlist[j+1] = nlist[j+1], nlist[j] nlist = [14,46,43,27,57,41,45,21,70] bubble_sort(nlist) print(nlist)
1st Sep 2018, 8:24 AM
Keerttik Titan
Keerttik Titan - avatar
1st Sep 2018, 9:38 AM
VcC
VcC - avatar