Consider a stack with the following elements: 5, 4, 3, 2 where the top element…
Consider a stack with the following elements: 5, 4, 3, 2 where the top element is 2. You need to transform the stack into the following state: 6, 5, 4, 3, 2 with 6 as the new top element. The only operations allowed are push() and pop(). Which sequence of operations achieves the desired stack configuration?
- A.
push(pop()), push(6), push(pop())
- B.
push(pop()), push(6)
- C.
push(pop()), push(pop()), push(6)
- D.
push(6)
Attempted by 71 students.
Sign up free to check your answer
Sign up freeLoading lesson…