Skip to content

Commit deb5d18

Browse files
Merge pull request #10 from YAKSHUMAKKAR39/main
Create Selectionsort.py
2 parents 469a07c + 191f94c commit deb5d18

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Selectionsort.py

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

0 commit comments

Comments
 (0)