diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-05-06 06:14:54 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-05-06 06:14:54 +0300 |
commit | d6de118675a192ce6e01574eb4eb2541db7aca7a (patch) | |
tree | f5899b5089029fc5637435482cce5e279fa5e2ce /insertion_sort.py | |
download | sorting-algorithms-d6de118675a192ce6e01574eb4eb2541db7aca7a.tar.gz sorting-algorithms-d6de118675a192ce6e01574eb4eb2541db7aca7a.zip |
initial commit
Diffstat (limited to '')
-rw-r--r-- | insertion_sort.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/insertion_sort.py b/insertion_sort.py new file mode 100644 index 0000000..9e0912d --- /dev/null +++ b/insertion_sort.py @@ -0,0 +1,15 @@ +# 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 insertion_sort(xs): + for i in range(1, len(xs)): + j = i + while j > 0 and xs[j - 1] > xs[j]: + xs[j], xs[j - 1] = xs[j - 1], xs[j] + j -= 1 + return xs + +if __name__ == '__main__': + import sys + print(insertion_sort(list(map(int, sys.argv[1:])))) |