Recursive calls and stack

jm.suresh@no.spam.gmail.com jm.suresh at gmail.com
Wed Feb 14 03:16:01 EST 2007


On Feb 14, 11:09 am, "jm.sur... at no.spam.gmail.com"
<jm.sur... at gmail.com> wrote:
> Hi,
>  I have a program which literately finds the object that overlapping a
> point. The horizontal and vertical search are called recursively from
> inside each other.
>  Is this way of implementation fill thestackspace with the local
> variables inside eachcall. If this is not good, is there a better way
> to implement? Orpythonitself will understand that the calls happen
> in the last line, so local variables need not be pushed into thestack?
>
> def find_point(pt):
>     return _hor_search(pt, random_obj)
>
> def _hor_search(pt, obj):
>     ...
>     object = ...
>     ...
>     if object meets some condition:
>         return object
>     else:
>         return _ver_search(pt, object)
>
> def _ver_search(pt, obj):
>     ...
>     object = ...
>     ...
>     if object meets some condition:
>         return object
>     else:
>         return _hor_search(pt, object)
>
> -
> Suresh

I found a simpler solution: get rid of recursive calls; using while
loops.

-
Suresh




More information about the Python-list mailing list