Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stopping Backtracking

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.

like image 632
John Retallack Avatar asked Oct 18 '25 10:10

John Retallack


1 Answers

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)

like image 108
Lie Ryan Avatar answered Oct 19 '25 23:10

Lie Ryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!