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 f082b8d

Browse files
Selection Sort in Python
1 parent 1f9fb6d commit f082b8d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎Sorting/selection sort.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#Sorting a list in Ascending Order using Selection Sort
2+
3+
#Selection sort function
4+
def selection_sort(alist):
5+
for i in range(0, len(alist) - 1):
6+
small = i
7+
for j in range(i + 1, len(alist)):
8+
if alist[j] < alist[small]:
9+
small = j
10+
alist[i], alist[small] = alist[small], alist[i]
11+
12+
# Taking a list of space seperated numbers from user
13+
alist = input('Enter the list of numbers: ').split()
14+
alist = [int(x) for x in alist]
15+
selection_sort(alist)
16+
print('Sorted list: ', end='')
17+
print(alist)

0 commit comments

Comments
(0)

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