0

Stack Data Structure

Hey guys! I got the question below from a book that I'm studying, but the answer of the book doesn't look correct for me. What the answer to the question below for you guys? Tks in advance. 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?

14th Feb 2018, 1:39 AM
Danito Le Dino
Danito Le Dino - avatar
1 ответ
+ 19
stack is working on the principle of last in first out so it will execute like this the sequence in the stack is 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 top is indicate the top most element in the stack so the value of top is 6
14th Feb 2018, 1:50 AM
GAWEN STEASY
GAWEN STEASY - avatar