📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      Consider a `Stack` data structure implemented with

      `push` and `pop` operations. What is the final state of the stack after the following sequence of operations?    ```     Stack s;     s.push(10);     s.push(20);     s.pop();     s.push(30);     s.push(40);     s.pop();     ```
      A [10,20,30,40](bottom to top) Correct Answer Incorrect Answer
      B [10,20,30](bottom to top) Correct Answer Incorrect Answer
      C [10,30](bottom to top) Correct Answer Incorrect Answer
      D [10,20,30](bottom to top) Correct Answer Incorrect Answer

      Solution

        Dry Run (Stack: Last In, First Out):            `s.push(10)`: Stack: `[10]`            `s.push(20)`: Stack: `[10, 20]`            `s.pop()`: Removes 20. Stack: `[10]`            `s.push(30)`: Stack: `[10, 30]`            `s.push(40)`: Stack: `[10, 30, 40]`            `s.pop()`: Removes 40. Stack: `[10, 30]`

      Practice Next
      ask-question