Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 293a5ab

Browse files
selection sort
1 parent 739f1c3 commit 293a5ab

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## SELECTION SORT
2+
3+
- I have an unordered list.
4+
- I find the smallest value in this list and set it to index 0.
5+
- Then I find the next smallest value and continue my search.
6+
7+
<img src="https://lh3.googleusercontent.com/proxy/jbSWXUD7nCXlB6UvnYwu70Uj5CrhrQWJs5JixA5vu7HD-yVxUF0yo29lUWu0-GI00cC1XPE1B43YsTPeHk2m0H5Bxd2cAg4Ju_4s4kYs-oT1mmKkR_E996kieZQOhNoqlVjmWDOTCMk"/>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def selection_sort(arr):
2+
3+
# for every slot in array
4+
for fillslot in range(len(arr)-1,0,-1):
5+
positionOfMax = 0
6+
7+
# for every set of 0 to fillslot+1
8+
for location in range(1,fillslot+1):
9+
# set maximum's location
10+
if arr[location]>arr[positionOfMax]:
11+
positionOfMax = location
12+
13+
temp = arr[fillslot]
14+
arr[fillslot] = arr[positionOfMax]
15+
arr[positionOfMax] = temp
16+
return arr
17+
18+
arr = [3,2,13,4,6,5,7,8,1,20]
19+
print("Output: ", selection_sort(arr))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /