Write a program to reverse a string using stack data structure ?
- Given a string, reverse it using stack. For example “Wikitechy” should be converted to “yhcetikiW”.
- Following is simple algorithm to reverse a string using stack.
-
- Empty stack to be created.
- String to stack put one by one push all characters.
- From the stack and put them back to string one by one pop all characters.

Sample Code in Java
Output
Reversed string is yhcetikiW.
Time Complexity:
- O(n) where n is number of characters in stack.