I've been learning push/pop data structures. So far I understand that the last item in is the first item out. The last item in will be at the bottom of the list in code view.
I know Push adds and Pop removes.
But I'm struggling to figure out this question.
What are the final contents of the stack after the following operations have been performed. The start is empty to begin with.
Probably means what are the values being held in the stack, it appears that there are more pushes than pulls so there should be some items still in the stack. What are they?
Before answer your question let me tell you one thing " push and pop are operations on Stack which follows the rule of LIFO( Last In First Out) ".
stackname.push(5);
stackname.push(14);
stackname.push(18);
stackname.pop();
stackname.push(5);
stackname.pop();
stackname.pop();
stackname.push(3);
----------------------------------Result-------------
_____
| 3 | 5 |
if you need full code for Stack visit http://khawa.6te.net/stack.html