Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- n = int(raw_input().strip())
- a = map(int, raw_input().strip().split(' '))
- numberofswaps = 0
- for i in range(n):
- j = 0
- while j < n - 1:
- if (a[j] > a[j+1] ):
- temp1 = a[j]
- temp2 = a[j+1]
- a[j] = temp2
- a[j+1] = temp1
- numberofswaps = numberofswaps + 1
- j=j+1
- if numberofswaps == 0:
- break
- print 'Array is sorted in ' + str(numberofswaps) + ' swaps.'
- print 'First Element: ' + str(a[0])
- print 'Last Element: ' + str(a[len(a)-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement