Skip to content

Commit

Permalink
Counting_Swaps_Selection_Sort
Browse files Browse the repository at this point in the history
  • Loading branch information
sinistergeek committed Apr 23, 2024
1 parent 832f583 commit 8e28eeb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Counting_Swaps_Selection_Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def count_swaps(lst):

swaps = 0

for i in range(len(lst)):
min_index = 1

for j in range(i+1,len(lst)):
if lst[j] < lst[min_index]:
min_index = j

if lst[i] < lst[min_index]:
lst[i],lst[min_index] = lst[min_index],lst[i]
swaps += 1

return swaps

data = list(map(int, input().split()))

result = count_swaps(data)

print(result)

0 comments on commit 8e28eeb

Please sign in to comment.