Skip to content

Commit bc35ffb

Browse files
committed
added selection sort
1 parent 6f8e99d commit bc35ffb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# program for selection sort
2+
#selections sort takes O(n^2) time complexity
3+
4+
5+
6+
#program starts from here
7+
def selectionSort( itemsList ):
8+
n = len( itemsList )
9+
for i in range( n - 1 ):
10+
minValueIndex = i
11+
12+
for j in range( i + 1, n ):
13+
if itemsList[j] < itemsList[minValueIndex] :
14+
minValueIndex = j
15+
16+
if minValueIndex != i :
17+
temp = itemsList[i]
18+
itemsList[i] = itemsList[minValueIndex]
19+
itemsList[minValueIndex] = temp
20+
21+
return itemsList

0 commit comments

Comments
 (0)