Insertion Sort - Part 1

  • + 0 comments

    python3

    def insertionSort1(n, arr):
        # Write your code here
        
        x = arr[-1]
        i = len(arr) - 2
        
        while x < arr[i] and i >= 0:
            arr[i+1] = arr[i]
            print(*arr)
            i = i - 1
            
        if i != len(arr) - 2:
            arr[i+1] = x
        
        print(*arr)