A stack is a linear Structure in which items may be added or removed only at one end, called the top of the stack. This means, in particular, the elements are removed from a stack in the reverse order of that which they are inserted in to the stack. The stacks are also called "Last-in First -Out (LIFO) " list.

Example
1. A stack of dinner plates on a kitchen.
2. "LAST HIRED, FIRST FIRED" which is typically utilized when a company wants to reduces its work force.
3. Remembering partially completed tasks. JVM uses a stack to remember all of a program's methods that have been called but are not yet finished.
4. undoing (backtracking from) an action. "undo" button on most text editors, which lets a person undo a typing error, or the "back" button on a web browser, which lets a user backtrack to a previous web page
5. In processing of subroutine calls and returns
Primary operations defined on a stack
Implementation of Stack:
The stack data structure can be implemented in two different ways
1. Using array [ Static Implementation ]
2. Using Linked List [ Dynamic Implementation ]
Array representation of a stack
Let us consider a stack with 3 elements capacity. This is called as the MaxSize of the stack. The number of elements to be added should not exceed the maximum size of the stack. If we attempt to add new element beyond the maximum size, we will encounter a stack overflow condition. Similarly, you cannot remove elements beyond the base of the stack. If such is the case, we will reach a stack underflow condition.
0 Comment to "Stack in Data Structure | Representation | Push and Pop operation"
Post a Comment