Stack Recursion

////I can’t understand what is wrong with this. it shows x is out of scope but when i use brackets in if else statements then it works completely fine.


@Ayush-Kokande-2816457821730452 i removed if and else its working fine whats the problem

if you use if else and there is more than one line u must use brackets i think you are mistaking in it
your else was only reading one line int x so out of else x was not declared and you were using it @Ayush-Kokande-2816457821730452

But my stack still is not reversed

yes because the code is not complete @Ayush-Kokande-2816457821730452

I pushed all elements in the stack and pushed all elements back into the same stack in backtracking what is wrong with it?

no in backtracking to the element u pop at last will be pushed first then so on …
so its same as it is @Ayush-Kokande-2816457821730452

here take a look https://ide.codingblocks.com/s/234132 its the correct code

u have to take the element from the top and then push it at the bottom using another recursive function @Ayush-Kokande-2816457821730452 is it clear?

Now i have understood. Thanks

ok just mark the doubt as resolved then @Ayush-Kokande-2816457821730452 :smiley: