Skip to content

Commit 6cbe2d5

Browse files
Selection Sort in Python
1 parent 3434109 commit 6cbe2d5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

sorting/selection-sort.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (C) Deepali Srivastava - All Rights Reserved
2+
# This code is part of DSA course available on CourseGalaxy.com
3+
4+
def selection_sort(a):
5+
for i in range(len(a)-1):
6+
minIndex = i
7+
for j in range(i+1,len(a)):
8+
if a[j] < a[minIndex]:
9+
minIndex = j
10+
if i!=minIndex:
11+
a[i],a[minIndex] = a[minIndex],a[i]
12+
13+
14+
####################################
15+
16+
list1 = [6,3,1,5,9,8]
17+
selection_sort(list1)
18+
print(list1)
19+
20+
list2 = [2,3,5,39,11,8,9,166,45,23]
21+
selection_sort(list2)
22+
print(list2)
23+
24+
list3 = [1,2,3,4,5,6,7,8,9,10]
25+
selection_sort(list3)
26+
print(list3)
27+
28+
list4 = [10,9,8,7,6,5,4,3,2,1]
29+
selection_sort(list4)
30+
print(list4)
31+
32+
list5 = [4]
33+
selection_sort(list5)
34+
print(list5)
35+
36+
#####################################
37+

0 commit comments

Comments
 (0)