Reverse a stack

sir please explain its reverse function by dry run , i didnt understood it

Hi @vikashkmr519,
See before understanding this you must be having knowledge of how a recursive call stacks builds in recursion … Like here we call the function reverseStack recursively again and again … So before calling each function recursively we store the current top value of stack in a item variable and the when the stack is empty we stop the recursive calls and then while every called function in the function stack is falling of returning we push the value of item in the helper stack . By this method we are able to copy all the values in original stack to the helper without disturbing the order of the stack . Therefore we can then pop the elements from helper stack and push them in the original stack to again maintain a stack with the reverse order .
I would recommend you to take a paper and a pen and follow along the video and make the recursive call stack and then follow along the video step by step to get a better idea.