Count Swap for Sorting in Python
Count Swap for Sorting
Hi Friends
Here I have coding for how many swaps occur during sorting the list.
I will help to score interviews..
So let's try and give your support..
Copy that Py Code and Paste Below mention website and run it...
website: https://repl.it/languages/python3
Here I have coding for how many swaps occur during sorting the list.
I will help to score interviews..
So let's try and give your support..
Copy that Py Code and Paste Below mention website and run it...
website: https://repl.it/languages/python3
CODE 1:
import sys
n = int(input().strip())
a = list(map(int, input().strip().split(' ')))
counter = 0
for x in range(len(a)-1):
for y in range(x+1, len(a)):
if a[x] > a[y]:
a[x],a[y] = a[y], a[x]
counter += 1
print('Array is sorted in', counter, 'swaps.')
print('First Element:', a[0])
print('Last Element:', a[len(a)-1])
----
By
Pykar
Comments
Post a Comment