Wednesday, June 19, 2013

Reversing the stack contents

Algorithm:

  1. Pop all the elements of stack till it becomes empty.
  2. After each recursive call, push the popped element at the bottom of stack.



Time Complexity: O(n^2)
Space Complexity: O(n): For recursion stack.

No comments:

Post a Comment