We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents c8cd7c6 + f082b8d commit 24edd89Copy full SHA for 24edd89
Sorting/selection sort.py
@@ -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