Return from recursive method !

Hi.

I have a project that have a recursive method. this method is a search method in a tree.

I want to return from depth n in tree.In other words,when mothod is called n time and find asolution in depth of n, runing method is stopped and return to main method and first call in stack.

plz help.

Thanks.



Answer this question

Return from recursive method !

  • cica

    Not sure how you are implementing the tree. Just in case if this is a Windows Form application, and if you are using TreeNode objects, then it has a Level property which tells you how deep the node is in the tree.
  • SteffenK

    Hi!

    This is simple: you can pass depth counter to the method params or you can declare field in the class and keep counter there.

  • Return from recursive method !