hello, could any one please send solution for followingquestion , Please mention
ID: 3609114 • Letter: H
Question
hello, could any one please send solution for followingquestion , Please mention each and every step.i.) Describe the output of the following series of stackoperations: push(8), push(3), pop(), push(2), push(5), pop( ), pop( ), push(9), push(1),pop( ), push(7), push(6), pop ( ), pop( ),push(4), pop( ), pop( ). hello, could any one please send solution for followingquestion , Please mention each and every step.
i.) Describe the output of the following series of stackoperations: push(8), push(3), pop(), push(2), push(5), pop( ), pop( ), push(9), push(1),pop( ), push(7), push(6), pop ( ), pop( ),push(4), pop( ), pop( ).
Explanation / Answer
think of a stack as a stack of plates. the only one you can get tois the one on top., and when you add a plate to the stack it goeson top. A stack is also called a LIFO (Last In First Out)structure, because the last item that was put on the stack is thefirst item to be removed. Adding something to a stack is pushing, removing something ispopping. so push 8 says add the number 8 to thestack. the stack has an 8 init 8 then you push 3 add a 3 to the stack. thestack now has an 8 on the bottom and a 3 on top ofit 3 8 pop you will now remove thetop item (the 3) from the stack leaving only the 8 init 8 push 2 add a 2 to thestack. the stack now has an 8 on the bottom and a 2 on top ofit 2 8 push 5 add a 5 to the stack.the stack now has an 8 on the bottom and a 2 on top of it anda 5 on top of that 5 2 8 pop you will nowremove the top item (the 5) from the stack leaving the 2 ontop and 8 on bottom 2 8 pop you will now removethe top item (the 2) from the stack leaving only the 8 init 8 continue like this until the list is done hope this clarifys
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.