Skip to content

Instantly share code, notes, and snippets.

@richardbwest
Created November 4, 2020 23:26
Show Gist options
  • Save richardbwest/73d4638cf0376f27609c8cc16614d45b to your computer and use it in GitHub Desktop.
Save richardbwest/73d4638cf0376f27609c8cc16614d45b to your computer and use it in GitHub Desktop.
Bubble Sort Algorithm Tutorial
import time,random
l = []
for i in range(20):
l.append(random.randint(1,1000))
def bubble_sort(l):
l = l[:]
while True:
swapped = False
for index in range(len(l)-1):
if l[index] > l[index+1]:
l[index], l[index+1] = l[index+1], l[index]
swapped = True
if swapped == False:
return(l)
sorted_list = bubble_sort(l)
print("sorted")
print(l)
print(sorted_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment