Created
May 22, 2018 22:49
-
-
Save scriptpapi/3cca7a29d1171f8fb51559b9c05bd1d4 to your computer and use it in GitHub Desktop.
simple bubble sort algorithm implementation
This file contains hidden or 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
| # 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