Skip to content

Commit 519524b

Browse files
authored
Create Selectionsort.py
1 parent eeb2499 commit 519524b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Selectionsort.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def selectionSort(array, size):
2+
3+
for ind in range(size):
4+
min_index = ind
5+
6+
for j in range(ind + 1, size):
7+
8+
if array[j] < array[min_index]:
9+
min_index = j
10+
11+
(array[ind], array[min_index]) = (array[min_index], array[ind])
12+
13+
arr = [-2, 45, 0, 11, -9,88,-97,-202,747]
14+
size = len(arr)
15+
selectionSort(arr, size)
16+
print('The array after sorting in Ascending Order by selection sort is:')
17+
print(arr)

0 commit comments

Comments
 (0)