skipping to a specific place in a recursive function
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: skipping to a specific place in a recursive function

  1. #1
    Join Date
    Apr 2009
    Posts
    1

    skipping to a specific place in a recursive function

    I wrote a recursive function that recurses Adding times, then calls go (). The entire function will call go () billions of times. When I call this function, I want to only run go () 5,000,000 times. It should run the first 5,000,000 go's if the Part variable is set to 1, the 2nd 5,000,000 go's if Part is 2, etc. The bolded code below is my attempt at implementing this. This code runs the correct 5,000,000-part pieces, but it takes too long because it is still recursing through every part, it's just not calling go () for the other ones. How can I only run the specific piece without recursing through all of the other ones?

    Code:
    Add (int X, int Y, int Adding)
    {
      int Tile;
      while (Y < 12)
      {
        while (X < 16)
        {
          if (aRoom [nRoom] [Y] [X] == 0)
          {
            Changes [Adding - 1] [1] = X;
            Changes [Adding - 1] [2] = Y;
            for (Tile = 0; aTiles [nRoom] [Tile] [0] != 0; Tile++)
            {
              if (aTiles [nRoom] [Tile] [1] > 0)
              {
                aTiles [nRoom] [Tile] [1]--;
                aRoom [nRoom] [Y] [X] = aTiles [nRoom] [Tile] [0];
                Changes [Adding - 1] [0] = aTiles [nRoom] [Tile] [0];
                if (Adding > 1)
                {
                  Add (X + 1, Y, Adding - 1);
                }
                else
                {
    PartTests++;
    if (Part == 0 || Part == Parts)
    {

    Code:
    go ();
    }
    if (PartTests == 5000000)
    {
    Parts++;
    PartTests = 0;
    }

    Code:
                }
                aTiles [nRoom] [Tile] [1]++;
              }
            }
            aRoom [nRoom] [Y] [X] = 0;
          }
          X++;
        }
        X = 0;
        Y++;
      }
    }

  2. #2
    Join Date
    Mar 2009
    Posts
    19

    Re: skipping to a specific place in a recursive function

    I'm having trouble understanding exactly what you want to achieve here. Do you think you could list the logical sequence of events you're aiming for? Then I might be able to help you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center