Skip to content
Related Articles

Related Articles

Data Structures | Stack | Question 4
  • Difficulty Level : Basic
  • Last Updated : 09 Feb, 2013
GeeksforGeeks - Summer Carnival Banner

Consider the following pseudocode that uses a stack

declare a stack of characters
while ( there are more characters in the word to read )
   read a character
   push the character on the stack
while ( the stack is not empty )
   pop a character off the stack
   write the character to the screen

What is output for input “geeksquiz”?

(A) geeksquizgeeksquiz
(B) ziuqskeeg
(C) geeksquiz
(D) ziuqskeegziuqskeeg

Answer: (B)

Explanation: Since the stack data structure follows LIFO order. When we pop() items from stack, they are popped in reverse order of their insertion (or push())

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :