September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,8 +1,8 @@
|
|||
def insertion_sort(l):
|
||||
for i in xrange(1, len(l)):
|
||||
def insertion_sort(L):
|
||||
for i in xrange(1, len(L)):
|
||||
j = i-1
|
||||
key = l[i]
|
||||
while (l[j] > key) and (j >= 0):
|
||||
l[j+1] = l[j]
|
||||
key = L[i]
|
||||
while (L[j] > key) and (j >= 0):
|
||||
L[j+1] = L[j]
|
||||
j -= 1
|
||||
l[j+1] = key
|
||||
L[j+1] = key
|
||||
|
|
|
|||
|
|
@ -1,15 +1,6 @@
|
|||
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:]
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,15 @@
|
|||
import bisect
|
||||
def insertion_sort_bin(seq):
|
||||
for i in range(1, len(seq)):
|
||||
bisect.insort(seq, seq.pop(i), 0, i)
|
||||
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