Insertion Sort - Part 2

  • + 2 comments

    I did about the same, but using a sentinel at the front of the array:

    n, amin = int(input()), -10**4
    A = [2*amin] + list(map(int, input().split()))
    for j in range(2, n+1):
        i, a = j, A[j]
        while a < A[i-1]:
            A[i] = A[i-1]
            i -= 1
        A[i] = a
        print(*A[1:])