Skip to content

Instantly share code, notes, and snippets.

@AntiKnot
Created April 2, 2020 05:26
Show Gist options
  • Select an option

  • Save AntiKnot/5f9c2fa38b211735b9d9f68e07300d96 to your computer and use it in GitHub Desktop.

Select an option

Save AntiKnot/5f9c2fa38b211735b9d9f68e07300d96 to your computer and use it in GitHub Desktop.
inset sort; 插入排序
import random
from typing import List
test_case = [2, 1, 3, 8, 0]
def insert_sort(l: List[int]) -> List[int]:
if l is []:
return []
length = len(l)
for i in range(1, length):
cur = l[i]
for j in range(i)[::-1]:
if l[j] < cur:
break
if l[j] >= cur:
l[j + 1] = l[j]
l[j] = cur
return l
if __name__ == '__main__':
print(insert_sort(test_case))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment