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


    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 (bottom to top) Correct Answer Incorrect Answer
    B (bottom to top) Correct Answer Incorrect Answer
    C (bottom to top) Correct Answer Incorrect Answer
    D (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