From 26c490f404731d053a6205719b6246502c07b449 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sat, 14 Jun 2014 16:46:27 +0200 Subject: init --- algorithms/insertion_sort.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 algorithms/insertion_sort.py (limited to 'algorithms/insertion_sort.py') diff --git a/algorithms/insertion_sort.py b/algorithms/insertion_sort.py new file mode 100755 index 0000000..ab786e0 --- /dev/null +++ b/algorithms/insertion_sort.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python2 + +import random + + +def insertion_sort(l): + sz = len(l) + for i in range(sz): + if i == 0: continue + j = i-1 + while l[i] < l[j] and j > -1: + j -= 1 + l.insert(j+1, l.pop(i)) + return l + +l = list(reversed(range(1000))) +#random.shuffle(l) +print l +print insertion_sort(l) + -- cgit v1.2.3