Consider you have a stack whose elements in it are as follows.
5 4 3 2 << top
Where the top element is 2.
You need to get the following stack
6 5 4 3 2 << top
The operations that needed to be performed are (You can perform only push and pop):
a) Push(pop()), push(6), push(pop())
b) Push(pop()), push(6)
c) Push(pop()), push(pop()), push(6)
d) Push(6)
Answer: a
Explanation: By performing push(pop()) on all elements on the current stack to the next stack you get 2 3 4 5 << top.Push(6) and perform push(pop()) you’ll get back 6 5 4 3 2 << top. You have actually performed enQueue operation using push and pop.
Related Posts
What is the result of the given postfix expression? abc*+ where a=1, b=2, c=3.
Which of the following statement is incorrect?
While evaluating a postfix expression, when an operator is encountered, what is the correct operation to be performed?
Which of the following is not an application of stack?
Which of these operators have the highest order of precedence?
In Postfix expressions, the operators come after the operands.
What is the time complexity of evaluation of postfix expression algorithm?
Join The Discussion