Step 1: Push All
Iterate through the string from left to right. Push each character onto the stack one by one.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
The most fundamental demonstration of the Last-In-First-Out (LIFO) property: pushing a sequence of characters and popping them out in reverse order.
Iterate through the string from left to right. Push each character onto the stack one by one.
Because the first character is pushed first, it sinks to the very bottom of the stack. The last character of the string ends up sitting at the very top.
Simply pop elements from the stack until it is empty, appending them to a new result string. The string is now magically reversed.