Created
June 24, 2016 18:41
-
-
Save KoderDojo/796eefaca435f08e5c4838b0711a836c to your computer and use it in GitHub Desktop.
Bubble Sort Using Python
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
import random | |
def BubbleSort(numbers): | |
swapped = True | |
maxIndex = len(numbers) - 1 | |
while swapped: | |
swapped = False | |
for i in range(maxIndex): | |
if numbers[i] > numbers[i + 1]: | |
numbers[i + 1], numbers[i] = numbers[i], numbers[i + 1] | |
swapped = True | |
maxIndex -= 1 | |
numbers = range(10) | |
random.shuffle(numbers) | |
print numbers | |
BubbleSort(numbers) | |
print numbers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment