Skip to content

Instantly share code, notes, and snippets.

@KoderDojo
Created June 24, 2016 18:41
Show Gist options
  • Save KoderDojo/796eefaca435f08e5c4838b0711a836c to your computer and use it in GitHub Desktop.
Save KoderDojo/796eefaca435f08e5c4838b0711a836c to your computer and use it in GitHub Desktop.
Bubble Sort Using Python
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