-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinsertion.py
More file actions
28 lines (27 loc) · 772 Bytes
/
insertion.py
File metadata and controls
28 lines (27 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from burstSettings import EOS
def sort(data, array, depth, L, R):
"""Sort the array using insertion sort. Actually this works
correctly when EOS == 0. Otherwise it works incorrectly when
comparing EOS and c < EOS.
"""
def less(a, b):
d = depth
while True:
c1 = data[a + d]
c2 = data[b + d]
if c1 < c2:
return True
if c2 < c1:
return False
if c1 == EOS == c2:
return False
d += 1
if len(array) < 2:
return
for i in xrange(L + 1, R):
j = i
temp = array[i]
while j > L and less(temp, array[j - 1]):
array[j] = array[j - 1]
j -= 1
array[j] = temp