summaryrefslogtreecommitdiff
path: root/algorithms/insertion_sort.py
blob: ab786e0c9fd129e2bd25d5005570d9774930a3de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)