insertion_sort

  • 2022-12-14
  • 浏览 (577)

insertion_sort.py 源码

# 插入排序
import random
from typing import List


def insertionSort(data: List[int]):
    length = len(data)
    if length <= 1:
        return

    for i in range(length - 1):
        j, k = i + 1, data[i + 1]
        while j > 0 and data[j - 1] > k:
            data[j] = data[j - 1]
            j -= 1
        data[j] = k

你可能感兴趣的文章

bubble_sort

merge_sort

quick_sort

0  赞