Sign in to follow this  

Simulated Recursiveness

This topic is 4691 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am always using recursiveness in my code, but I don't know how it 'really' works. So I pulled out a simulated recursive factorial function. It was based on a big while loop with a fundemantal list holding data for each simulated call. Pretty much like the one generated by the call stack in an authentic c++ recursive function. Yet an issue arises. I need to simulate something more complex, like a fibonacci recursive function with two calls per each new call. In this case my brain goes blank... [code] struct Body { // arguementdata ... ... // List Pointers Body *pNext, *pPrevious; // Return Value int ReturnValue; // Or any other type // Constructors and Other stuff.. ... } int factorial(int x) { Body Parent( x ); // initializes the struct with an Body *Active = &Parent; while( !Active->isDone ) { if( ... ) // simplest case scenario ( ie x == 0 ) { // Set the Return Value... Active = Active->pBefore; } else if( Active->pNext ) // A value is returned from next node { // Delete next node and return based on the data given from that node } else if( Active->pNext == 0 ) { // Create a new node and shift execution to that node } } return Parent.ReturnValue; } [\code] Hope that was self explanary enough... The thing am asking for is the generalization of such built-in stack lists for function calls (even with multi calls)... Please HELP!

Share this post


Link to post
Share on other sites
It's convenient that you decided to ask that now. One of the featured articles seems to be the exact answer to your question: http://www.gamedev.net/reference/programming/features/af7/

Share this post


Link to post
Share on other sites

This topic is 4691 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this