Assuming that you designed this program and then coded this from the design - then you know how it's supposed to work. As it's not then the first thing to do is to use the debugger to debug the program - trace the execution path, watch the variable contents etc. When this deviates from that expected then you're found a problem - which is either with the coding or the design. Fix that. Then repeat this until the program works as expected.
Debugging is a skill which needs to be acquired and honed. Unfortunately this is very often either not taught or not taught well.
Probably. This is where a debugger can help, so you can step through your function and see where it is going awry. In general, recursion is more confusing that iteration, so I tend to avoid recursive functions except for tree-like structures (personally). I would prefer a while loop in this situation.
Lines 25 & 28: You have an if-else chain here. It's either going to enter one branch, or the other, and you have return statements in both branches. Therefore, lines 34 and beyond will never be hit. If there is vital logic within those lines, it will never happen.
I would also add checks before you pop_back to make sure your container has at least 1 element in it.
Alright, I will comment and test each line and see what happens! And no, the code is an homework. I solved the unhandled exception but my logic is still not generating the correct output. I must use recursive (which is very new to me) I will update the code.