Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F94002307
merge_.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Dec 3, 04:10
Size
992 B
Mime Type
text/x-python
Expires
Thu, Dec 5, 04:10 (2 d)
Engine
blob
Format
Raw Data
Handle
22700884
Attached To
rMARAFFO Master-cycle
merge_.py
View Options
# array, start, middle, end
def
merge_count
(
A
,
s
,
m
,
end
):
# sizes
nl
=
m
-
s
nr
=
end
-
m
# counter
c
=
0
# output list
out
=
[]
# indices
l
=
s
r
=
m
# loop over and sort
while
l
<
nl
or
r
<
nr
:
if
l
==
nl
:
# l can still be increased
out
.
append
(
A
[
r
])
r
+=
1
if
l
<
nl
:
# exclude sentinel case
#inversion detected
#print("Inversion detected: (%f, %f)" % (L[l], R[r]))
c
+=
nl
-
l
elif
r
==
nr
:
# r can still be increased
out
.
append
(
A
[
l
])
l
+=
1
elif
A
[
r
]
<
A
[
l
]:
out
.
append
(
A
[
r
])
r
+=
1
if
l
<
nl
:
# exclude sentinel case
#inversion detected
#print("Inversion detected: (%f, %f)" % (L[l], R[r]))
c
+=
nl
-
l
else
:
out
.
append
(
A
[
l
])
l
+=
1
return
c
,
out
Event Timeline
Log In to Comment