Last active
August 29, 2015 14:09
-
-
Save prasadwrites/6878e0ed8f70677f4dea to your computer and use it in GitHub Desktop.
BubbleSort
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
#! /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