Skip to content

Commit 18e8f0f

Browse files
committed
Create selectionsort.py
1 parent a702455 commit 18e8f0f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

selectionsort.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from generator import Generator
2+
3+
4+
def SelectionSort(arr: list) -> list:
5+
for i in range(len(arr)):
6+
min_i = i # minimum element in remaining unsorted array
7+
for j in range(i + 1, len(arr)):
8+
if arr[min_i] > arr[j]:
9+
min_i = j
10+
11+
# Swap the minimum element with the first element
12+
arr[i], arr[min_i] = arr[min_i], arr[i]
13+
14+
return arr
15+
16+
17+
if __name__ == '__main__':
18+
arr = Generator(1000)
19+
sorted_list = SelectionSort(arr)
20+
print(sorted_list)

0 commit comments

Comments
 (0)