# Simulated Recursiveness

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

## 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! 
 0 
 Share this post Link to post Share on other sites 
 
 
 Advertisement Sure Shot    140 Sure Shot Member 140 Posted February 13, 2005 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/ 0 Share this post Link to post Share on other sites 
 Sign in to follow this   Followers 0 
 Go To Topic Listing General and Gameplay Programming Advertisement 
 Advertisement Popular Tags 2D 3D Advice Algorithm C# C++ Concept Design DX11 Education Financial GameMaker Gameplay General HTML5 Java Javascript Mobile Music OpenGL PC SFX Unity Unreal Visual Studio Popular Contributors Week Month Year All Time 1 Rutin 25 2 lawnjelly 24 3 fleabay 19 4 Gnollrunner 18 5 Hodgman 15 Show More Advertisement Popular Now 9 Taking the First Step By JaLue2002Started Tuesday at 10:12 PM 10 Calculate the amount of torque impulse needed to get to a certain orientation. By AxiverseStarted Tuesday at 11:17 AM 13 Symbol lookup error on Linux By GuyWithBeardStarted Tuesday at 11:07 AM 19 C# Making Decisions In Text Adventures! By JustHuskStarted Monday at 06:55 PM 14 solving x*V1 + y*V2 = V3 By Max PowerStarted Saturday at 09:59 PM Who's Online (See full list) There are no registered users currently online GameDev.net GameDev.net Articles GameDev.net Event Coverage GameDev.net Forums GameDev.net Blogs GameDev.net Gallery GameDev.net News GameDev.net Projects GDNet Chat All Activity Search In Everywhere This Forum This Topic More options... Find results that contain... All of my search term words Any of my search term words Find results in... Content titles and body Content titles only Home Forums Programming General and Gameplay Programming Simulated Recursiveness 
 
 
 × Existing user? Sign In Sign Up Browse Back Articles & Tutorials Back All Categories Audio Business Game Design Industry Programming Visual Arts Columns Back GameDev Unboxed Event Coverage Back All Events Game Developers Conference Power Up Digital Games Conference GameDev.Market Links News Podcasts Back All Podcasts Game Dev Loadout Archive Community Back Beginners Back Beginners Group Beginners Forum Beginners Resources Blogs Calendar Chat Forums Back All Forums Audio Business Game Design Programming Visual Arts Community GameDev Challenges Affiliates Topical Workshops Gallery Groups Back For Beginners GameDev Challenges All Groups Projects Back All Projects Games Game Assets Game Mods Developer Tools Store Forums Back All Forums For Beginners Audio Back Music and Sound FX Games Career Development Business Back Games Career Development Production and Management Games Business and Law Game Design Back Game Design and Theory Writing for Games Programming Back Artificial Intelligence Engines and Middleware General and Gameplay Programming Graphics and GPU Programming Math and Physics Networking and Multiplayer Visual Arts Back 2D and 3D Art Critique and Feedback Community Back GameDev Challenges GDNet Lounge GDNet Comments, Suggestions, and Ideas Coding Horrors Your Announcements Hobby Project Classifieds Indie Showcase Affiliates Back NeHe Productions AngelCode Topical Workshops Careers Back Contractors Hobby Projects Game Jobs Back Browse on GameDev.Jobs Post a Job Members Back Subscriptions Chat Guidelines Leaderboard Online Users Awards Search Back All Activity My Activity Streams Back Latest Topics Featured Blogs Search var ipsDebug=false;var CKEDITOR_BASEPATH='//www.gamedev.net/applications/core/interface/ckeditor/ckeditor/';var ipsSettings={cookie_path:"/",cookie_prefix:"ips4_",cookie_ssl:true,upload_imgURL:"",message_imgURL:"",notification_imgURL:"",baseURL:"//www.gamedev.net/",jsURL:"//www.gamedev.net/applications/core/interface/js/js.php",csrfKey:"ccfae769b4c16ccceea1bc41b1846e7b",antiCache:"14de000c45",disableNotificationSounds:false,useCompiledFiles:true,links_external:true,memberID:0,analyticsProvider:"ga",viewProfiles:true,mapProvider:'google',mapApiKey:"AIzaSyAeT7tk3vnWWmbgVISkLpbhkQvekG19rHM",}; ips.setSetting('date_format',jQuery.parseJSON('"mm\/dd\/yy"'));ips.setSetting('date_first_day',jQuery.parseJSON('0'));ips.setSetting('remote_image_proxy',jQuery.parseJSON('1'));ips.setSetting('ipb_url_filter_option',jQuery.parseJSON('"none"'));ips.setSetting('url_filter_any_action',jQuery.parseJSON('"allow"'));ips.setSetting('bypass_profanity',jQuery.parseJSON('0'));ips.setSetting('emoji_style',jQuery.parseJSON('"native"'));ips.setSetting('emoji_shortcodes',jQuery.parseJSON('"1"'));ips.setSetting('emoji_ascii',jQuery.parseJSON('"1"'));ips.setSetting('emoji_cache',jQuery.parseJSON('"1"'));ips.setSetting('quickSearchDefault',jQuery.parseJSON('"all"'));ips.setSetting('quickSearchMinimum',jQuery.parseJSON('3'));ips.setSetting('quickSearchShowAdv',jQuery.parseJSON('true'));ips.setSetting('quickSearchIn',jQuery.parseJSON('"title"')); { "@context": "http://schema.org", "@type": "DiscussionForumPosting", "url": "https://www.gamedev.net/forums/topic/300648-simulated-recursiveness/", "discussionUrl": "https://www.gamedev.net/forums/topic/300648-simulated-recursiveness/", "name": "Simulated Recursiveness", "headline": "Simulated Recursiveness", "text": "I am always using recursiveness in my code, but I don\u0027t know how it \u0027really\u0027 works.\nSo 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.\n\nYet 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...\n\n\nstruct Body\n{\n // arguementdata ...\n ...\n // List Pointers\n Body *pNext, *pPrevious;\n // Return Value\n int ReturnValue; // Or any other type\n // Constructors and Other stuff..\n ...\n}\n\nint factorial(int x)\n{\n Body Parent( x ); // initializes the struct with an\n Body *Active = \u0026amp;Parent;\n while( !Active-\u0026gt;isDone )\n {\n if( ... ) // simplest case scenario ( ie x == 0 )\n {\n // Set the Return Value...\n Active = Active-\u0026gt;pBefore;\n }\n else if( Active-\u0026gt;pNext ) // A value is returned from next node\n {\n // Delete next node and return based on the data given from that node\n }\n else if( Active-\u0026gt;pNext == 0 )\n {\n // Create a new node and shift execution to that node\n }\n }\n return Parent.ReturnValue;\n}\n[\\code]\n\nHope that was self explanary enough...\nThe thing am asking for is the generalization of such built-in stack lists for function calls (even with multi calls)...\n\nPlease HELP!", "dateCreated": "2005-02-13T10:51:34+0000", "datePublished": "2005-02-13T10:51:34+0000", "pageStart": 1, "pageEnd": 1, "image": "https://secure.gravatar.com/avatar/d4f57c1c19ded981ddd02f6deae931c0?d=https://www.gamedev.net/uploads/monthly_2017_08/A.png.644f8739d32007081e6b2cefef086b2d.png", "author": { "@type": "Person", "name": "arithma", "image": "https://secure.gravatar.com/avatar/d4f57c1c19ded981ddd02f6deae931c0?d=https://www.gamedev.net/uploads/monthly_2017_08/A.png.644f8739d32007081e6b2cefef086b2d.png", "url": "https://www.gamedev.net/profile/76506-arithma/" }, "interactionStatistic": [ { "@type": "InteractionCounter", "interactionType": "http://schema.org/ViewAction", "userInteractionCount": 192 }, { "@type": "InteractionCounter", "interactionType": "http://schema.org/CommentAction", "userInteractionCount": 1 }, { "@type": "InteractionCounter", "interactionType": "http://schema.org/FollowAction", "userInteractionCount": 18 } ], "comment": [ { "@type": "Comment", "url": "https://www.gamedev.net/forums/topic/300648-simulated-recursiveness/?do=findComment\u0026comment=300648", "author": { "@type": "Person", "name": "arithma", "image": "https://secure.gravatar.com/avatar/d4f57c1c19ded981ddd02f6deae931c0?d=https://www.gamedev.net/uploads/monthly_2017_08/A.png.644f8739d32007081e6b2cefef086b2d.png", "url": "https://www.gamedev.net/profile/76506-arithma/" }, "dateCreated": "2005-02-13T10:51:34+0000", "text": "I am always using recursiveness in my code, but I don\u0027t know how it \u0027really\u0027 works.\nSo 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.\n\nYet 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...\n\n\nstruct Body\n{\n // arguementdata ...\n ...\n // List Pointers\n Body *pNext, *pPrevious;\n // Return Value\n int ReturnValue; // Or any other type\n // Constructors and Other stuff..\n ...\n}\n\nint factorial(int x)\n{\n Body Parent( x ); // initializes the struct with an\n Body *Active = \u0026amp;Parent;\n while( !Active-\u0026gt;isDone )\n {\n if( ... ) // simplest case scenario ( ie x == 0 )\n {\n // Set the Return Value...\n Active = Active-\u0026gt;pBefore;\n }\n else if( Active-\u0026gt;pNext ) // A value is returned from next node\n {\n // Delete next node and return based on the data given from that node\n }\n else if( Active-\u0026gt;pNext == 0 )\n {\n // Create a new node and shift execution to that node\n }\n }\n return Parent.ReturnValue;\n}\n[\\code]\n\nHope that was self explanary enough...\nThe thing am asking for is the generalization of such built-in stack lists for function calls (even with multi calls)...\n\nPlease HELP!", "mainEntityOfPage": "https://www.gamedev.net/forums/topic/300648-simulated-recursiveness/" }, { "@type": "Comment", "url": "https://www.gamedev.net/forums/topic/300648-simulated-recursiveness/?do=findComment\u0026comment=2909290", "author": { "@type": "Person", "name": "Sure Shot", "image": "https://secure.gravatar.com/avatar/186536e0d7feba0d3664182349718036?d=https://www.gamedev.net/uploads/monthly_2017_08/S.png.5353023e549917724557fef20f4ee927.png", "url": "https://www.gamedev.net/profile/76662-sure-shot/" }, "dateCreated": "2005-02-13T16:58:07+0000", "text": "It\u0027s 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/", "mainEntityOfPage": "https://www.gamedev.net/forums/topic/300648-simulated-recursiveness/" } ] } { "@context": "http://www.schema.org", "@type": "WebSite", "name": "GameDev.net", "url": "https://www.gamedev.net/", "potentialAction": { "type": "SearchAction", "query-input": "required name=query", "target": "https://www.gamedev.net/search/?q={query}" }, "inLanguage": [ { "@type": "Language", "name": "English (USA)", "alternateName": "en-US" } ] } { "@context": "http://www.schema.org", "@type": "Organization", "name": "GameDev.net", "url": "https://www.gamedev.net/", "address": { "@type": "PostalAddress", "streetAddress": "", "addressLocality": null, "addressRegion": null, "postalCode": null, "addressCountry": null } } { "@context": "http://schema.org", "@type": "BreadcrumbList", "itemListElement": [ { "@type": "ListItem", "position": 1, "item": { "@id": "https://www.gamedev.net/forums/", "name": "Forums" } }, { "@type": "ListItem", "position": 2, "item": { "@id": "https://www.gamedev.net/forums/forum/4-programming/", "name": "Programming" } }, { "@type": "ListItem", "position": 3, "item": { "@id": "https://www.gamedev.net/forums/forum/9-general-and-gameplay-programming/", "name": "General and Gameplay Programming" } } ] } { "@context": "http://schema.org", "@type": "ContactPage", "url": "https://www.gamedev.net/contact/" } Important Information By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.   I accept 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!