Difference between PUSH and POP

Key difference: PUSH is when an entry is "pushed onto" the stack. POP is when the last pushed entry is "popped off" the stack.

PUSH and POP are commands used on a stack. In computer science, a stack is an area of memory that holds all local variables and parameters used by any function. This is essential as a stack remembers the order in which functions are called so that function returns occur correctly.

A stack is a restricted data structure, because only a small number of operations are performed on it. A stack is named due to its ability to place individual data entries in a stack, like a stack of books. The first entry goes in the bottom, and corresponding entries are placed on top of the first entry. However, if something from the middle or bottom of the stack needs to be accessed, then everything on top of that entry must be removed first, before gaining access to the entry. This type of arrangement is called LIFO (Last In, First Out).

The two main fundamental operations regarding a stack is the PUSH and POP functions. The POP function is also sometimes called PULL. Essentially, the PUSH operation adds a new item to the top of the stack, or initializes the stack if it is empty. The POP operation, on the other hand, removes an item from the top of the stack. A pop either reveals previously concealed items, or results in an empty stack.

An empty stack is considered to be in an underflow state, which essentially states that there are no items present in the stack. When a function is called, its local variables and parameters are "pushed onto" the stack. Nonetheless this is the PUSH function. When the function returns, these locals and parameters are "popped off." This is the POP function. Due to this, the size of a program's stack fluctuates constantly as the program is running. However, each stack has a maximum size. When the stack is considered to be full, it is in an overflow state.

The nature of the PUSH and POP operations also means that stack elements have a natural order. Elements are removed from the stack in the reverse order to the order of their addition. This signifies that the lower elements have been on the stack longer; therefore the lowest element has been there the longest. The elements on the top are the newer elements.

Image Courtesy: alpcentauri.info, p4program.blogspot.in

Most Searched in Arts and Humanities Most Searched in Environment
Most Searched in Home and Garden Most Searched Non-Alcoholic Drinks
HTML5 vs PHP
Web Hosting vs Web Publishing
Hyundai i20 vs Maruti Suzuki Swift
Nokia Lumia 925 vs iPhone 5

Add new comment

Plain text

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.