Reverse a stack using recursion You are not allowed to use loop constructs like while, for..etc, and you can only use the following ADT functions on Stack S: isEmpty(S) push(S) pop(S) Solution: The idea of the solution is to hold all values in Function Call Stack until the stack becomes empty. When the stack becomes empty, insert all held items one by one at the bottom of the stack. For example, let the input stack be 1 <-- top 2 3 4 First 4 is inserted at the bottom.
Read full article from Reverse a stack using recursion | GeeksforGeeks
No comments:
Post a Comment