Skip to main content

Stack – Reverse a String using Stack

Learn how to reverse a String using Stack. In this example takes in an array based Stack.

Stack – Data Structure  – Array-based and Linked list based implementation.

The followings are the steps to reversing a String using Stack.

  • String to Char[].
  • Create a Stack.
  • Push all characters, one by one.
  • Then Pop all characters, one by one and put into the char[].
  • Finally, convert to the String.

Time complexity – O(n)

Space complexity – O(n)

Complete Example

output :-



Related Post

679total visits,1visits today

RSS
Follow by Email
Facebook
Facebook
Google+
http://mydevgeek.com/stack-reverse-string-using-stack
Twitter