Skip to content

Instantly share code, notes, and snippets.

@ombak
Last active May 30, 2020 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ombak/c270e19b7f491ecdd9611b438ebff018 to your computer and use it in GitHub Desktop.
Save ombak/c270e19b7f491ecdd9611b438ebff018 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
def bubbleSort(mylist):
# outer loop
for i in range(len(mylist)-1, 0, -1):
# inner loop
for j in range(i):
if mylist[j] > mylist[j+1]:
# swap the value
temp = mylist[j]
mylist[j] = mylist[j+1]
mylist[j+1] = temp
return mylist
firstlist = [5, 8, 3, 1]
print(bubbleSort(firstlist))
# RESULT
# [1, 3, 5, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment