Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Created May 26, 2017 03:03
Show Gist options
  • Save pinglunliao/741f1d3a5b740aff80923ff705723bab to your computer and use it in GitHub Desktop.
Save pinglunliao/741f1d3a5b740aff80923ff705723bab to your computer and use it in GitHub Desktop.
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