Mô phỏng thuật toán Sắp xếp chèn

Insertion Sort · Nhóm: Sắp xếp

Sắp xếp chèn (Insertion Sort), nhóm Sắp xếp.

Mã Python

def insertion_sort(a):
    for i in range(1, len(a)):
        key = a[i]
        j = i - 1
        while j >= 0 and a[j] > key:
            a[j + 1] = a[j]
            j -= 1
        a[j + 1] = key
    return a

Mở trang để xem mô phỏng từng bước và xuất slide bài giảng.