Question-23
Python programming
Stack
Queue
Suppose a stack implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE (with respect to this modified stack)?
Answer
Solution
With the REVERSE instruction, a queue can be implemented using this modified stack where ENQUEUE would require a sequence of three instructions (REVERSE, PUSH, REVERSE), and DEQUEUE would require a single instruction (POP).