I'm not a student of algorithms. Perhaps if you gave a few examples of the sort of data and data structures you want to sort, I could provide some ideas and code examples.
I once wrote a recursive depth-first search that used a stack, and the lack of local variables was a hurdle there also. I was able to work around this somewhat gracefully using arrays. Where you would normally push something onto the stack, I would increment my pointer to the top of the $stack array and add the value there.
Code:
setVar $stacktop ($stacktop + 1)
setVar $stack[$stacktop] $someValue
And at the start of my loop, I would set a local variable to $stack[$stacktop]
Here is a snippet from the heart of that routine:
Code:
:loop
while ($stackTop > 0)
setVar $focus $stack[$stackTop]
add $warpIndex[$focus] 1
setVar $warp $warpIndex[$focus]
while ($warp <= SECTOR.WARPCOUNT[$focus])
setVar $adjacent SECTOR.WARPS[$focus][$warp]
if ($checked[$adjacent] = 0)
# Push it onto the Stack
add $stackTop 1
setVar $stack[$stackTop] $adjacent
setVar $checked[$adjacent] 1
gosub :checkAdjacents
gosub :loop
# This is the return point when we POP off the Stack
end
setVar $focus $stack[$stackTop]
add $warpIndex[$focus] 1
setVar $warp $warpIndex[$focus]
end
# At an end point, record path by traversing the stack
gosub :recordPath
gosub :clearChecked
subtract $stackTop 1
if ($stackTop < 1)
echo "*StackTop=" $stackTop ", halting.*"
pause
halt
end
gosub :checkPath
end
return
The other problem that I had to overcome in that routine was keeping track of which warp I was on for a given sector. You can see that I'm tracking that with another array, due to the global variable limitation. I'm substituting $warpIndex[SECTOR] in place of what would otherwise be $warp if local variables existed.
Anyway, I know that the above is complex, but I hope it is of some help in understanding how you can overcome the lack of local variables. If there is enough interest, I could comment it up well, and post it to Grimy ( & navhaz )
+EP+