Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,8 @@
|
|||
def insertion_sort(L):
|
||||
for i in xrange(1, len(L)):
|
||||
j = i-1
|
||||
key = L[i]
|
||||
while j >= 0 and L[j] > key:
|
||||
L[j+1] = L[j]
|
||||
j -= 1
|
||||
L[j+1] = key
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
def insertion_sort(L):
|
||||
for i, value in enumerate(L):
|
||||
for j in range(i - 1, -1, -1):
|
||||
if L[j] > value:
|
||||
L[j + 1] = L[j]
|
||||
L[j] = value
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
def insertion_sort_bin(seq):
|
||||
for i in range(1, len(seq)):
|
||||
key = seq[i]
|
||||
# invariant: ``seq[:i]`` is sorted
|
||||
# find the least `low' such that ``seq[low]`` is not less then `key'.
|
||||
# Binary search in sorted sequence ``seq[low:up]``:
|
||||
low, up = 0, i
|
||||
while up > low:
|
||||
middle = (low + up) // 2
|
||||
if seq[middle] < key:
|
||||
low = middle + 1
|
||||
else:
|
||||
up = middle
|
||||
# insert key at position ``low``
|
||||
seq[:] = seq[:low] + [key] + seq[low:i] + seq[i + 1:]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import bisect
|
||||
def insertion_sort_bin(seq):
|
||||
for i in range(1, len(seq)):
|
||||
bisect.insort(seq, seq.pop(i), 0, i)
|
||||
Loading…
Add table
Add a link
Reference in a new issue