Created
May 26, 2017 02:49
-
-
Save pinglunliao/3424af46f61c6f8a7fbe9a8e5697dc71 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 insertion_sort(lst): | |
if len(lst) == 1: | |
return lst | |
for i in range(1, len(lst)): | |
temp = lst[i] | |
j = i - 1 | |
while j >= 0 and temp < lst[j]: | |
lst[j + 1] = lst[j] | |
j -= 1 | |
lst[j + 1] = temp | |
return lst | |
print "Original Data:", unsortData | |
sortData = insertion_sort(unsortData); | |
print "Sorted Data:", sortData |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment