Skip to content

Commit fcfe14c

Browse files
authored
Update selection-sort.py
1 parent 00e53ae commit fcfe14c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def selection_sort(lst):
2+
n = len(lst)
3+
i = 0
4+
5+
while i < n - 1:
6+
smallest = i
7+
j = i + 1
8+
9+
while j < n:
10+
if lst[j] < lst[smallest]:
11+
smallest = j # находим наименьшее число
12+
j+=1
13+
14+
lst[i], lst[smallest] = lst[smallest], lst[i] # меняем местами, наименьшее "вначало"
15+
16+
#print(lst)
17+
18+
i+=1
19+
20+
return lst

0 commit comments

Comments
 (0)