saurabh-verma12
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
23 additions and
0 deletions
-
selection sort program
|
|
@ -0,0 +1,23 @@ |
|
|
|
# Python program for implementation of Selection |
|
|
|
# Sort |
|
|
|
import sys |
|
|
|
A = [64, 25, 12, 22, 11] |
|
|
|
|
|
|
|
# Traverse through all array elements |
|
|
|
for i in range(len(A)): |
|
|
|
|
|
|
|
# Find the minimum element in remaining |
|
|
|
# unsorted array |
|
|
|
min_idx = i |
|
|
|
for j in range(i+1, len(A)): |
|
|
|
if A[min_idx] > A[j]: |
|
|
|
min_idx = j |
|
|
|
|
|
|
|
# Swap the found minimum element with |
|
|
|
# the first element |
|
|
|
A[i], A[min_idx] = A[min_idx], A[i] |
|
|
|
|
|
|
|
# Driver code to test above |
|
|
|
print ("Sorted array") |
|
|
|
for i in range(len(A)): |
|
|
|
print("%d" %A[i]), |