Re: who can do this without the recursion
| From: | Richard Lynch | Date: | Tue, 05 Jul 2005 21:07:21 +0000 |
| Subject: | Re: who can do this without the recursion | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-218154@lists.php.net to get a copy of this message | ||
On Tue, July 5, 2005 3:48 am, Jochem Maas said:
> I have a function which recursively loops an assoc array in
> order to build an HTML string containing hidden <input> elements
> that repesent the key/values passed in the array ... I know this can
> be done without recursion but I'm having a brainfreeze, anyone care
> to share some tips on replacing the recursion with some kind of stack
> based solution (the idea being that I want to remove the overhead
> of the recursive calls to the function if possible ...
I don't recall the answer, but if you Google for "eliminate tail
recursion" or "convert tail recursion to iteration" you should find
Computer Science textbook examples galore.
You'd think having done a zillion of these in my Grad School days would
have made more of an impression...
Mostly it impressed me that recursion wasn't "cool" -- just another "tool"
and one that you only should pull out 1% of the time.
I have a hacksaw. I don't use it every meal.
--
Like Music?
http://l-i-e.com/artists.htm