Menu
![](/uploads/1/2/5/7/125750828/639886074.jpg)
The rifle clip analogy posted by Oren A is pretty good, but I'll try another one and try to anticipate what the instructor was trying to get across.A stack, as it's name suggests is an arrangement of 'things' that has:. A top. A bottom. An ordering in between the top and bottom (e.g. Second from the top, 3rd from the bottom).(think of it as a literal stack of books on your desk and you can only take something from the top)Pushing something on the stack means 'placing it on top'.Popping something from the stack means 'taking the top 'thing' off the stack.A simple usage is for reversing the order of words.
The POP instruction causes the status of the current PRINT, USING or ACONTROL instruction to be overridden by the PRINT, USING or ACONTROL status saved by the last PUSH instruction. Push Pop® Mystery Flavor Flavors include Blue Raspberry, Berry Blast, Watermelon, and Strawberry and the NEW limited edition Mystery Flavor! Flavors include Blue Raspberry, Berry Blast, Watermelon, Strawberry, and NEW limited edition Mystery Flavor!
![Push Push](https://vignette.wikia.nocookie.net/a-little-curious/images/1/17/Bob_the_Ball.png/revision/latest?cb=20181128002127)
Say I want to reverse the word: 'popcorn'. I push each letter from left to right (all 7 letters), and then pop 7 letters and they'll end up in reverse order. It looks like this was what he was doing with those expressions.push(p)push(o)push(p)push(c)push(o)push(r)push(n)after pushing the entire word, the stack looks like: n. Thanks for some feedback guys, @matt i didnt mean to be insulting to the man, but imo he's not as good a teacher compared to the rest of my lecturers in my other modules, programming, comp org, comp maths, comp apps, sorry if the word crap offends you. I am in college in Ireland Nix, and adam shankman isnt my real name, so no fear of any repercussions there lol, any how back to my predicament i dont understand how we convert 2.3/(2-1)+5.(4-1) to final answer +/.23-21.5-41 via the push pop, He gave a 30 minute lecture and my notes aren't much good!!–Sep 29 '10 at 20:11. A stack in principle is quite simple: imagine a rifle's clip - You can only access the topmost bullet - taking it out is called 'pop', inserting a new one is called 'push'.A very useful example for that is for applications that allow you to 'undo'.Imagine you save each state of the application in a stack. The state of the application after every type the user makes.Now when the user presses 'undo' you just 'pop' the previous state from the stack.
For every action the user does - you 'push' the new state to the stack (that's of course simplified).About what your lecturer specifically was doing - in order to explain it some more information would be helpful. As the other answerers explained, a stack is a last-in, first-out data structure. You add an element to the top of the stack with a Push operation. You take an element off the top with a Pop operation. The elements are removed in reverse order to the order they were put inserted (hence Last In, First Out). For example, if you push the elments 1,2,3 in that order, the number 3 will be at the top of the stack. A Pop operation will remove it (it was the last in) and leave 2 at the top of the stack.Regarding the rest of the lecture, the lecturer tried to describe a stack-based machine that evaluates arithmetic expressions.
The machine operates by continuously popping 3 elements from the top of the stack. The first two elements are operands and the third is an operator (+, -,., /). It then applies this operator on the operands, and pushes the result onto the stack. The process continues until there is only one element on the stack, which is the value of the expression.So, suppose we begin by pushing the values '+/.23-21.5-41' in left-to-right order onto the stack. We then pop 3 elements from the top.
The last in is first out, which means the first 3 element are '1', '4', and '-' in that order. We push the number 3 (the result of 4-1) onto the stack, then pop the three topmost elements: 3, 5,. Push the result, 15, onto the stack, and so on.
PUSH vs POPA stack is a structure that is used in programming. Resogun guide. There are two basic operations that can be performed on a stack to modify its contents, which are called PUSH and POP. The main difference between PUSH and POP is what they do with the stack.
PUSH is used when you want to add more entries to a stack while POP is used to remove entries from it.A stack is so named because it places the individual entries just like a stack of books. The first one goes to the bottom and you can only add or remove items at the top of the stack. If you want something from the middle or bottom of the stack, you need to first remove everything on top of it in order to get the item you want. This is often referred to as a Last In, First Out structure or LIFO.Aside from how they modify the stack, there are also differences on the commands or the arguments they take to be specific. PUSH takes two arguments, the name of the stack to add the data to and the value of the entry to be added. In comparison, POP only needs the name of the stack and the value is no longer relevant.
POP automatically removes the entry at the stop of the stack or the one that was last added to it.When adding, there is always a point where you can’t add anymore. When the stack is filled and another PUSH command is issued, you get a stack overflow error. It basically tells you that the stack can no longer accommodate the last PUSH. And with POP, a stack underflow error occurs when you try to POP an already empty stack. These errors basically tell you the limits of your stack and can be captured to provide an or to provide a cleaner and more informative error to the user or programmer.Stacks are quite important tools, despite being quite simple, in programming.
Programs that utilize stacks intensively have other operations built on top of PUSH and POP that either provides better functionality or simplifies commonly done tasks.Summary:1.PUSH is used to add an item to a stack while POP is used to remove an item to the stack2.PUSH takes two arguments while POP only takes one.
![](/uploads/1/2/5/7/125750828/639886074.jpg)