Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,61 @@
|
|||
merge: function [a,b,left,middle,right][
|
||||
leftLen: middle - left
|
||||
rightLen: right - middle
|
||||
|
||||
l: 0
|
||||
r: leftLen
|
||||
|
||||
loop left..dec middle 'i [
|
||||
b\[l]: a\[i]
|
||||
l: l + 1
|
||||
]
|
||||
loop middle..dec right 'i [
|
||||
b\[r]: a\[i]
|
||||
r: r + 1
|
||||
]
|
||||
|
||||
l: 0
|
||||
r: leftLen
|
||||
i: left
|
||||
|
||||
while [and? l < leftLen r < leftLen + rightLen][
|
||||
if? b\[l] < b\[r] [
|
||||
a\[i]: b\[l]
|
||||
l: l + 1
|
||||
]
|
||||
else [
|
||||
a\[i]: b\[r]
|
||||
r: r + 1
|
||||
]
|
||||
i: i + 1
|
||||
]
|
||||
|
||||
while [l < leftLen][
|
||||
a\[i]: b\[l]
|
||||
l: l + 1
|
||||
i: i + 1
|
||||
]
|
||||
while [r < leftLen + rightLen][
|
||||
a\[i]: b\[r]
|
||||
r: r + 1
|
||||
i: i + 1
|
||||
]
|
||||
]
|
||||
|
||||
mergeLR: function [a,b,left,right][
|
||||
if 1 >= right - left -> return ø
|
||||
mid: (left + right) / 2
|
||||
mergeLR a b left mid
|
||||
mergeLR a b mid right
|
||||
merge a b left mid right
|
||||
]
|
||||
|
||||
mergeSort: function [arr][
|
||||
result: new arr
|
||||
b: new array.of:size result 0
|
||||
|
||||
mergeLR result b 0 size result
|
||||
return result
|
||||
]
|
||||
|
||||
print mergeSort [3 1 2 8 5 7 9 4 6]
|
||||
Loading…
Add table
Add a link
Reference in a new issue