Created
October 15, 2014 07:11
-
-
Save KentaYamada/b5d1c03c4e55e301ae37 to your computer and use it in GitHub Desktop.
挿入ソート(Python)
This file contains hidden or 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
# -*- coding:utf-8 -*- | |
def insertation_sort(arr): | |
for i in range(1, len(arr)): | |
j = i | |
while(j > 0 and arr[j - 1] > arr[j]): | |
tmp = arr[j - 1] | |
arr[j - 1] = arr[j] | |
arr[j] = tmp | |
j = j - 1 | |
return arr | |
if __name__ == '__main__': | |
arr = [3, 9, 6, 1, 2] | |
print (arr) | |
arr = insertation_sort(arr) | |
print (arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment