refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-07-13 15:52:56 +02:00
parent 4650a2934b
commit 1d9d4fcc78
4 changed files with 2 additions and 50 deletions
-39
View File
@@ -5,45 +5,6 @@ public.LT = {}
public.EQ = {}
public.GT = {}
-- stable sorting
function public.merge_sort(A, comp)
local n = getn(A)
local B = {}
local width = 1
while width <= n do
for i=1, n, 2 * width do
private.merge(A, i, min(i + width, n), min(i + 2 * width - 1, n), B, comp)
end
private.copy_array(B, A, n)
width = 2 * width
end
end
function private.merge(A, start1, start2, last, B, comp)
local i1 = start1
local i2 = start2
for i=start1,last do
if i1 < start2 and (i2 > last or comp(A[i1], A[i2]) == public.LT or comp(A[i1], A[i2]) == public.EQ) then
B[i] = A[i1]
i1 = i1 + 1
else
B[i] = A[i2]
i2 = i2 + 1
end
end
end
function private.copy_array(A, B, n)
for i=1,n do
B[i] = A[i]
end
end
function public.invert_order(ordering)
if ordering == public.LT then
return public.GT