user3622142
user3622142

Reputation: 370

stack pop and push performaing on empty

The question is: The following series of operations are performed on an empty stack, list the contents of the stack after these operations have completed?

Push 12
Push 2
Pop
Push 8
Push 23
Push 4
Pop
Pop
Push 63

My answer: 12, 8 , 63

It is because they pushed in 12, 2 and then poped so the last number that was in is the first one out which leaves 12. Then added 8,24 and 4 but then popped twice which leave 12, 8 and then pushed 63 which leaves the final answer the 12, 8 and 64

Can someone comfirm if I am right or wrong? If I am wrong why? I would also like to ask, if we flush does they remove all the number or only check is all the numbers have been completed?

Upvotes: 1

Views: 608

Answers (1)

Manoj
Manoj

Reputation: 314

You are right. Here is the stack after every step: 12 12 2 12 12 8 12 8 23 12 8 23 4 12 8 23 12 8 12 8 63 After all operations you are left with 12 8 and 63.

Upvotes: 1

Related Questions