PrepAway - Latest Free Exam Questions & Answers

What is the value of the top element after these operations are executed?

You have a stack that contains integer values. The values are pushed onto the stack in the
following order: 2,4,6,8.
The following sequence of operations is executed:
Pop
Push 3
Pop
Push 4
Push 6
Push 7

Pop
Pop
Pop
What is the value of the top element after these operations are executed?

PrepAway - Latest Free Exam Questions & Answers

A.
2

B.
3

C.
6

D.
7

6 Comments on “What is the value of the top element after these operations are executed?

  1. Serge says:

    Tested is C.6

    Stack numbers = new Stack();

    numbers.Push(2);
    numbers.Push(4);
    numbers.Push(6);
    numbers.Push(8);

    numbers.Pop();
    numbers.Push(3);
    numbers.Pop();
    numbers.Push(4);
    numbers.Push(6);
    numbers.Push(7);
    numbers.Pop();
    numbers.Pop();
    numbers.Pop();

    foreach (int n in numbers)
    Console.WriteLine(n);




    1



    0
  2. Cam Vale says:

    Answer is 6

    2,4,6,8
    Pop() 2,4,6
    Push(3) 2,4,6,3
    Pop() 2,4,6
    Push(4) 2,4,6,4
    Push(6) 2,4,6,4,6
    Push(7) 2,4,6,4,6,7
    Pop() 2,4,6,4,6
    Pop() 2,4,6,4
    Pop() 2,4,6




    1



    0

Leave a Reply