This happens a lot when you have a function call itself recursively.
This is what
QS_int() seems to be doing.
My advise is find a way to write a formula or put the code in a loop until it comes out with what you want it to do.
Edit1: Hopefully, I successfully integrated a loop in the code to stop the recursive calling and produce the same result. I'm still not sure what the code is supposed to do, but it should be fixed now. It'll either work or be thrown into an infinite loop. *shrugs*
Edit2: Revised the code again, discovered a possibility that wouldn't have resulted in the code running exactly the same way as OP.
Edit3: Hopefully the last revision now that I've worked around with the code a little. I'm still seeing a lot of possibilities for infinite loops, for example, any time
pe is
nil. This might be what caused the problem in the first place. Added an
else break clause to prevent it.
Edit4: Corrected variable contamination before the last check.
lua Code:
local function QS_int(left,right,t,c)
if left < right then
local l, r = left, right
while l < r then
local pe = t[floor((l+r)/2)][c] -- pivot element
if pe then
while l < r do
if t[l][c] then while t[l][c] > pe do l = l + 1 end end
if t[r][c] then while t[r][c] < pe do r = r - 1 end end
if l <= r then
local tItem = t[l]
t[l] = t[r]
t[r] = tItem
l = l + 1
r = r - 1
end
end
else
break
end
local tl, tr = l, r
if left < tr then l=left end
if right > tl then r=right end
end
end
end