So I had to make this backtracking app, and I decided to make it also recursive, the app must do this:
"User inputs N numbers , then a S number , generate all possible numbers created from the N numbers lesser than S
i.e: For user input N = 3(0,2,3) and S = 300 the app will generate 2 < 300, 20 < 200 , 203 < 300 , 222 < 300 etc."
The application works for inputs > 0, but when i put 0 as input , the whole screen will be filled with 0's and the app will crash, I dont really understand why...
That looks complicated, as in difficult to follow, debug, maintain, etc.
It definitely has undefined behaviour, because the first call to backt() calls first afis(), which dereferences uninitialized sol.
How about nonrecursive:
1. Store digits in ordered container D.
2. Calculate how many digit positions is in S.
3. For each position* in S iterate over D. A combination is X.
4. Append each valid X into std::set R.
5. Show R.
[*] you could limit the most significant digits prefixes to <= of the prefix of S.
well thanks for help , i figured it out before seeing your post , when inputing 0 , the index was overflowing the array with integers i solved that by putting a if(index > lung) with a break statement in the for of the generation function... now works like wonders , btw i forgot to tell that i wanted to be efficient and thats why i did not used a iterative version