Skip to content

Commit bb7778b

Browse files
authored
Created Selectionsort.py
1 parent 1ccfd4c commit bb7778b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

selectionsort.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Python program for implementation of Selection
2+
# Sort
3+
import sys
4+
A = [64, 25, 12, 22, 11]
5+
6+
# Traverse through all array elements
7+
for i in range(len(A)):
8+
9+
# Find the minimum element in remaining
10+
# unsorted array
11+
min_idx = i
12+
for j in range(i+1, len(A)):
13+
if A[min_idx] > A[j]:
14+
min_idx = j
15+
16+
# Swap the found minimum element with
17+
# the first element
18+
A[i], A[min_idx] = A[min_idx], A[i]
19+
20+
# Driver code to test above
21+
print ("Sorted array")
22+
for i in range(len(A)):
23+
print("%d" %A[i]),

0 commit comments

Comments
 (0)