Is there any way in C/C++ to stop a backtracking algorithm after finding the first solution without exiting the program.
I want my function to immediately exit the function,not to quit every level of recurrsion one by one stating return.
A quick and dirty way is to throw an Exception and catch it at the base level (around right now a lot of people will scream to only use Exceptions for Errors, I argue, founding a solution is an exceptional event since not finding one is the norm)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With