Skip to content

Instantly share code, notes, and snippets.

@KentaYamada
Created October 15, 2014 07:11
Show Gist options
  • Save KentaYamada/b5d1c03c4e55e301ae37 to your computer and use it in GitHub Desktop.
Save KentaYamada/b5d1c03c4e55e301ae37 to your computer and use it in GitHub Desktop.
挿入ソート(Python)
# -*- 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