Created
May 26, 2017 03:03
-
-
Save pinglunliao/741f1d3a5b740aff80923ff705723bab to your computer and use it in GitHub Desktop.
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; | |
unsortData = random.sample(range(100), 10) | |
def bubble_sort(List): | |
for j in range(len(List)-1,0,-1): | |
flag = True | |
for i in range(0, j): | |
if List[i] > List[i+1]: | |
flag = False | |
List[i], List[i+1] = List[i+1], List[i] | |
if flag: | |
return List | |
return List | |
print "Original Data:", unsortData | |
sortData = bubble_sort(unsortData); | |
print "Sorted Data:", sortData |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment