aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/selection_sort.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-05-06 06:14:54 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-05-06 06:14:54 +0300
commitd6de118675a192ce6e01574eb4eb2541db7aca7a (patch)
treef5899b5089029fc5637435482cce5e279fa5e2ce /selection_sort.py
downloadsorting-algorithms-d6de118675a192ce6e01574eb4eb2541db7aca7a.tar.gz
sorting-algorithms-d6de118675a192ce6e01574eb4eb2541db7aca7a.zip
initial commit
Diffstat (limited to 'selection_sort.py')
-rw-r--r--selection_sort.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/selection_sort.py b/selection_sort.py
new file mode 100644
index 0000000..c466bea
--- /dev/null
+++ b/selection_sort.py
@@ -0,0 +1,17 @@
+# Copyright 2015 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is licensed under the terms of the MIT License.
+# See LICENSE.txt for details.
+
+def selection_sort(xs):
+ for i in range(len(xs) - 1):
+ min_i = i
+ for j in range(i + 1, len(xs)):
+ if xs[j] < xs[min_i]:
+ min_i = j
+ if min_i != i:
+ xs[i], xs[min_i] = xs[min_i], xs[i]
+ return xs
+
+if __name__ == '__main__':
+ import sys
+ print(selection_sort(list(map(int, sys.argv[1:]))))