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

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

  1. R says:

    Stack uses the First in Last Out method.

    Correct answer is 6.

    Its like compiling books in a box where in you always pop the books at the top and when you pushed a book, it will be on top.




    1



    0
  2. Pro says:

    6 is the Right answer…

    Stack i = new Stack();

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

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

    foreach(var item in i){
    Console.WriteLine(“{0} “, item);
    }




    1



    0

Leave a Reply