Skip to content

Instantly share code, notes, and snippets.

@zigzackey
Created March 29, 2016 15:44
Show Gist options
  • Save zigzackey/c4920928cd4b666dbd1a to your computer and use it in GitHub Desktop.
Save zigzackey/c4920928cd4b666dbd1a to your computer and use it in GitHub Desktop.
def selectionSort(A, N):
global cnt
for i in range(N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if i != minj:
tmp = A[i]
A[i] = A[minj]
A[minj] = tmp
cnt = cnt + 1 #
return A
if __name__ == '__main__':
n = int(input())
R = list(map(int, input().split()))
cnt = 0
R = selectionSort(R, n)
print(" ".join(map(str, R)))
print(cnt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment