• + 0 comments
    n = int(input().strip())
    a = list(map(int, input().rstrip().split()))
    c=0
    for x in range(n-2,-1,-1):
        for i in range(0,x+1):
            if a[i]>a[i+1]:
                t=a[i] 
                a[i]=a[i+1]
                a[i+1]=t   
                c+=1
    print(f"Array is sorted in {c} swaps.")
    print(f"First Element: {a[0]}")
    print(f"Last Element: {a[-1]}")