Data Structures · Question 2 · Easy

Starting with an empty stack, Kavya performs: push(5), push(8), push(3), pop(), push(7), pop(). Which element is now on top of the stack?

  1. 5
  2. 8
  3. 3
  4. 7
Answer and explanation

Answer: B. 8

Explanation: After push 5, 8, 3 the stack is 5 8 3; pop removes 3; push 7 gives 5 8 7; pop removes 7. The top is 8.

Previous: Which data structure works on the Last-In-First-Out (LIFO) principle? · Next: Starting with an empty queue: enqueue(A), enqueue(B), enqueue(C), dequeue()…

Practise data structures

Try a fresh set of data structures questions with an explanation after every answer, free and without signing up: Data Structures practice. Or sit a full placement mock test.

More data structures questions

More technical & programming practice

Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge