Skip to content

Instantly share code, notes, and snippets.

@scriptpapi
Created May 22, 2018 22:49
Show Gist options
  • Select an option

  • Save scriptpapi/3cca7a29d1171f8fb51559b9c05bd1d4 to your computer and use it in GitHub Desktop.

Select an option

Save scriptpapi/3cca7a29d1171f8fb51559b9c05bd1d4 to your computer and use it in GitHub Desktop.
simple bubble sort algorithm implementation
# simple bubble sort implementation
import random
def bubbleSort(iList):
for i in range(len(iList)):
try:
if iList[i] > iList[i+1]:
tmp = iList[i]
iList[i] = iList[i+1]
iList[i+1] = tmp
else:
continue
except IndexError:
continue
for i in range(len(iList)):
try:
if iList[i] < iList[i + 1]:
continue
else:
bubbleSort(iList)
except IndexError:
continue
return iList
testList = random.sample(range(1, 100), 5)
print(testList)
print(bubbleSort(testList))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment