Skip to content

Commit ded6c69

Browse files
author
Amogh Singhal
authored
Create selection_sort.py
1 parent 212e161 commit ded6c69

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

selection_sort.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# A simple implementation of Selection Sort
2+
3+
def selectionSort(arr):
4+
i = 0
5+
while i < len(arr):
6+
min_index = i
7+
for j in range(i+1, len(arr)):
8+
if arr[j] < arr[min_index]:
9+
min_index = j
10+
11+
arr[i], arr[min_index] = arr[min_index], arr[i]
12+
i = i + 1
13+
14+
return arr
15+
16+
arr = [2, 6, 1, 5, 3, 4]
17+
res = selectionSort(arr)
18+
print(res)
19+

0 commit comments

Comments
 (0)