Is there any way to totally exit from the recursion stack in c++. For example I am searching for some goal state using recussion and when I found that just print it and come out from all the recussion stack.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The most straightforward way to do this (whether this is stylistically the best is questionable) is likely via wrapping your recursive function in a
try/catchblock, and then exiting via throwing a custom exception of some sort that contains the results of your calculation. This will automatically unwind your stack to the level of yourtry/catchblock, and then you can proceed from there.