Skip to content

Commit 265b0a0

Browse files
Create selectionsort.py
Created a selection sort program using python.
1 parent 28f7947 commit 265b0a0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: python/selectionsort.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def selectionSort(alist):
2+
for fillslot in range(len(alist)-1,0,-1):
3+
positionOfMax=0
4+
for location in range(1,fillslot+1):
5+
if alist[location]>alist[positionOfMax]:
6+
positionOfMax = location
7+
8+
temp = alist[fillslot]
9+
alist[fillslot] = alist[positionOfMax]
10+
alist[positionOfMax] = temp
11+
12+
alist = [54,26,93,17,77,31,44,55,20]
13+
selectionSort(alist)
14+
print(alist)

0 commit comments

Comments
 (0)