减慢递归函数中的循环速度
我有一个关于递归函数的难题。本质上,我需要“减慢”重复调用自身(函数)的函数中的 for 循环; 这是可能的,还是我需要以某种方式提取函数的递归性质?
function callRecursiveFuncAgain(ob:Object):void{
//do recursive stuff;
for (var i:int = 0; i < 4; i++) {
_nextObj=foo
callRecursiveFuncAgain(_nextObj);
}
}
I have a difficult problem with a recursive function. Essentially I need to 'slow down' a for loop within a function that repeatedly calls itself(the function);
Is this possible, or do I need to somehow extract the recursive nature of the function?
function callRecursiveFuncAgain(ob:Object):void{
//do recursive stuff;
for (var i:int = 0; i < 4; i++) {
_nextObj=foo
callRecursiveFuncAgain(_nextObj);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试设置超时
Try setTimeout
您应该使用一些需要等待一段时间的函数或另一个会使用大量 CPU 的函数,因此会减慢递归函数的速度。另一种方法是使用调试器和断点。
You should use some function which will wait for some time or another function which will use much CPU and therefore will slow down your recursive function. Another way would be using debugger and breakpoints.
你是认真的?如果您的计算机速度较慢,则您的 CPU 的负载会比速度较快的 CPU 更高,而在需要良好解决方案的情况下,它永远无法工作。它甚至还不是一个蹩脚的解决方案。
尝试使用 flash.utils 包中的 setTimeOut http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html。
示例使用:setTimeout(delayedFunction, 延迟, 参数);
请注意,延迟以毫秒表示。
检查“clearTimeOut()”函数 (flash.utils) 以在完成后清除 setTimeOut。
Are you serious? If you have a slow computer your CPU will have more load then a fast CPU which will NEVER work in a situation that needs a good solution. It's not even close to a crappy solution.
Try to use the setTimeOut that's in the flash.utils package http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html.
example use: setTimeout(delayedFunction, delay, arguments);
Note that the delay is expressed in milliseconds.
Check the 'clearTimeOut()' function (flash.utils) to clear your setTimeOut when you're done with it.