Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8628285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:29:53+00:00 2026-06-12T08:29:53+00:00

I was wondering how (or maybe even if it’s possible) to implement recursion without

  • 0

I was wondering how (or maybe even if it’s possible) to implement recursion without a separate function that calls itself.
So far all algorithms implementing recursion I’ve seen use a separate function. I thought a lot and came up with the idea that a goto statement with some variable mutation can do the job but I’m really unsure about that.
I made a mini research and found info about this Structured programming theorem which proves that every algorithm can be implemented with only three data structures, so such a recursion implementation must be posible but I still cannot assemble everything into consistent knowledge and understanding for the whole would-be approach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:29:54+00:00Added an answer on June 12, 2026 at 8:29 am

    What you are looking for is basically expressing a recursive function into an iterative form.
    This can easily be done by using a Stack. Here’s a very simple example in C#:

    int NodeCount(Node n)
    {
          if (n.Visited) return 0; // This node was visited through another node, discard
          n.Visited = true;
          int res = 1;
          foreach (Node ni in n.Children) // Recurse on each node
          {
                res += NodeCount(ni); // Add the number of sub node for each node
          }
          return res;           
    }
    

    Here’s the exact same function in iterative form:

    int NodeCount(Node root)
    {
        int res = 0;
        Stack<int> stk = new Stack<int>();
        stk.Push(root) // We start with the root node
        while( stk.Count > 0) // While we still have nodes to visit
        {
              Node current = stk.Pop(); // Get the node on top of the stack
              current.Visited = true;  // Mark it as visited
              res ++; // Add one to the count
              foreach (Node ni in n.Children) // Push all non visited children to the stack
              {     
                    if (ni.Visited == false) 
                            stk.Push(ni);
              }
    
        }
        return res;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering if anyone has any good tutorials(or maybe even a library that
I'm wondering if there is a standard way in c#(or maybe even cli) to
Is it possible for a function in C++ to find the addresses of all
Wondering if this is even possible or a limitation of PHP, googling around seems
I am wondering if maybe ReSharper is able to run through every class and
Maybe the title could be rephrased slightly better but basically I'm wondering how the
I was wondering which is the way to make this simple (and maybe stupid)
Wondering if any of you can help me: I've made a signup modal that
Wondering if there is any way to get the lambda expressions that result from
I'm wondering, what would be the best way of leaving code writers (programmers) information/initials/(maybe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.