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?
A.
2
B.
3
C.
6
D.
7
Answer is C.6
Answer is C.6
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);
is 6!!!!
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
As everyone mentioned, its 6!