Jump to content
  • Advertisement
Sign in to follow this  
arithma

Simulated Recursiveness

This topic is 4903 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... 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!