Difference Between PUSH and POP
PUSH vs POP
A stack is a data structure that is used in programming. 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 data 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 alternative 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 stack
2.PUSH takes two arguments while POP only takes one
- Difference Between Sony Cybershot S Series and W Series - December 22, 2012
- Difference Between Samsung Galaxy S3 and iPhone 5 - December 21, 2012
- Difference Between Samsung Galaxy S2 (Galaxy S II) and Galaxy S 4G - December 20, 2012
Search DifferenceBetween.net :
Email This Post : If you like this article or our site. Please spread the word. Share it with your friends/family.
I like this method of getting information.