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

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

Sắp xếp chọn (Selection Sort), nhóm Sắp xếp.

Mã Python

def selection_sort(a):
    n = len(a)
    for i in range(n):
        min_idx = i
        for j in range(i + 1, n):
            if a[j] < a[min_idx]:
                min_idx = j
        a[i], a[min_idx] = a[min_idx], a[i]
    return a

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