dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Recursion involving tree with many branches and all branches need to be stored

  1. #1
    Join Date
    Dec 2014
    Posts
    1

    Recursion involving tree with many branches and all branches need to be stored

    I want to store all the result which are basically 8 points generated after every time function
    GenTestPoint is called.

    Can you suggest me how to store all the points generated i.e 4096+512+64+8 points. However, I mainly need the 4096 points which are generated at the end. I am new to programming, not much familiar with pointer and all stuff.

    Its start from level 1.

    Level 1 = 8 Points;
    Level 2 = 64 points;
    Level 3 = 512 Points;
    Level 4 = 4096 points;
    8 points will be calculated only when if statement is true. But it's fine in the worst case all the statements are true and at the end we will get 4096 points. Just consider that all the if statements are true and I am getting 4096 points at the end which I need to store in some GLOBAL Variable.

    I need this 4096 points at the end, but even if you can suggest me to store all the points at the end, then also its good.

    void GenTestPoint(Vec3f test, float level)
    {

    float new_denominator = pow(2.0f,level);
    Vec3f result1, result2, result3, result4, result5, result6, result7, result8;
    Vec3f result11, result12, result13, result14, result15, result16, result17, result18;

    result1 = (test.x - 1/new_denominator, test.y - 1/new_denominator, test.z - 1/new_denominator);

    result2 = (test.x - 1/new_denominator, test.y - 1/new_denominator, test.z + 1/new_denominator);

    result3 = (test.x + 1/new_denominator, test.y - 1/new_denominator, test.z + 1/new_denominator);

    result4 = (test.x + 1/new_denominator, test.y - 1/new_denominator, test.z - 1/new_denominator);

    result5 = (test.x + 1/new_denominator, test.y + 1/new_denominator, test.z - 1/new_denominator);

    result6 = (test.x - 1/new_denominator, test.y + 1/new_denominator, test.z - 1/new_denominator);

    result7 = (test.x - 1/new_denominator, test.y + 1/new_denominator, test.z + 1/new_denominator);

    result8 = (test.x + 1/new_denominator, test.y + 1/new_denominator, test.z + 1/new_denominator);

    while (level < 5)
    {
    if (CheckInOut(result1)= true)
    GenTestPoint(result1, level);
    else
    break;

    if (CheckInOut(result2)= true)
    GenTestPoint(result2, level);
    else
    break;

    if (CheckInOut(result3) = true)
    GenTestPoint(result3, level);
    else
    break;
    if (CheckInOut(result4)= true)
    GenTestPoint(result4, level);
    else
    break;

    if (CheckInOut(result5)= true)
    GenTestPoint(result5, level);
    else
    break;

    if (CheckInOut(result6)= true)
    GenTestPoint(result6, level);
    else
    break;

    if (CheckInOut(result7)= true)
    GenTestPoint(result7, level);
    else
    break;

    if (CheckInOut(result8)= true)
    GenTestPoint(result8, level);
    else
    break;
    level = level + 1;
    }


    }

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,451

    Re: Recursion involving tree with many branches and all branches need to be stored

    Quote Originally Posted by ayush15 View Post
    Code:
    while (level < 5)
    {
        if (CheckInOut(result1)= true)
            GenTestPoint(result1, level);
        else
            break;
    }
    If you thought this
    Code:
         (CheckInOut(result1)= true)
    is a comparison operator then you are wrong. This is an assignment!
    You should write it like
    Code:
         if(CheckInOut(result1) == true)
    or much better, just
    Code:
         if(CheckInOut(result1))
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,810

    Re: Recursion involving tree with many branches and all branches need to be stored

    When posting code, please use code tags. Go Advanced, select the formatted code and click '#'.

    As this is a recursive function and there are 8 results per function call, do you just want to store the 8 results per call or do you want to store additional info such as level, CheckInOut () result etc. You mention 4096 points - but this is still 512 sets of 8 points and as your function is currently coded only these 8 points can be stored at one time.

    One easy way would be to simply sequentially write the results to a file - but what is stored and how it is best stored depends somewhat on how the data is to be used.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.2.5)

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)