Data Structures | Stack | Question 4

Last Updated :
Discuss
Comments

Consider the following pseudocode that uses a stack 

Python
# Declare a stack of characters
word = "example"  # Replace with the word you want to read
char_stack = []

# While there are more characters in the word to read
for c in word:
    char_stack.append(c)  # Push the character on the stack

# While the stack is not empty
while char_stack:
    c = char_stack.pop()  # Pop a character off the stack
    print(c, end='')  # Write the character to the screen

What is output for input "geeksquiz"?

geeksquizgeeksquiz

ziuqskeeg

geeksquiz

ziuqskeegziuqskeeg

Share your thoughts in the comments