• Advertisement
Sign in to follow this  

.x file: How to use loops to traverse the tree structure

This topic is 978 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 probably cannot get the number of children within that structure.

I mean the hierarchy because it isn't a member variable in the D3DXFRAME structure.

I sometimes would want to iterate a lot of frames, Is it an absolute thing to do it by recursion,

because I am getting stack overflows. I got about 50000 custom frames, so the C++ program cannot hold

that many frames on the stack by recursion, which is quite unsatisfactory.

Any ideas I can work around this?

Thanks

Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites
Advertisement
Don't know XNA nor directX, but the general strategy to avoid recursion is to have a 'notdone' list, a list of nodes you still have to visit.

while (!notdone.is_empty()) {
    node = notdone.pop(); // Get one of the nodes.
    // Do something with 'node'
    for (Node child : node.childs) { // Add childs to the 'notdone' list.
        notdone.append(child);
    }
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement