• + 0 comments

    Python 3 code if name == 'main': n = int(input().strip())

    a = list(map(int, input().rstrip().split()))
    
    swapy = 0
    for i in range(n):
        for j in range(n-1):
            wartosc = int()
            if (a[j] > a[j + 1]):
                wartosc = a[j]
                a[j] = a[j + 1]
                a[j + 1] = wartosc
                swapy += 1
    
    print("Array is sorted in "+str(swapy)+ " swaps.")
    print("First Element: " +str(a[0]))
    print("Last Element: " + str(a[-1]))