Skip to content

Instantly share code, notes, and snippets.

@prasadwrites
Last active August 29, 2015 14:09
Show Gist options
  • Save prasadwrites/6878e0ed8f70677f4dea to your computer and use it in GitHub Desktop.
Save prasadwrites/6878e0ed8f70677f4dea to your computer and use it in GitHub Desktop.
BubbleSort
#! /usr/env/path python
arr = [6,5,4,7,8,4,3,2,1,45,23,67,34]
def bubble_sort(arr):
swapped, j = True, 1
length = len(arr)
while(swapped):
swapped = False
for i in range(0,length-j):
if( arr[i] >= arr[i+1] ):
temp = arr[i]
arr[i] = arr[i+1]
arr[i+1] = temp
swapped = True
j += 1
print(arr)
bubble_sort(arr)
print(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment