Last active
May 30, 2020 14:30
-
-
Save ombak/c270e19b7f491ecdd9611b438ebff018 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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