8000
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.
1 parent 62e8655 commit d89e7d3Copy full SHA for d89e7d3
sorting/selection_sort.py
@@ -0,0 +1,26 @@
1
+from __future__ import print_function
2
+
3
4
+def selection_sort(collection):
5
6
+ length = len(collection)
7
+ for i in range(length):
8
+ least = i
9
+ for k in range(i + 1, length):
10
+ if collection[k] < collection[least]:
11
+ least = k
12
+ collection[least], collection[i] = (
13
+ collection[i], collection[least]
14
+ )
15
+ return collection
16
17
18
+if __name__ == '__main__':
19
+ try:
20
+ raw_input # Python 2
21
+ except NameError:
22
+ raw_input = input # Python 3
23
24
+ user_input = raw_input('Enter numbers separated by a comma:\n').strip()
25
+ unsorted = [int(item) for item in user_input.split(',')]
26
+ print(selection_sort(unsorted))
0 commit comments