Created
March 29, 2016 15:44
-
-
Save zigzackey/c4920928cd4b666dbd1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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