What is Stack Data Structure? Stack is a simple data structure used for storing similar type.
1. Key Point of Stack
- Stack is an ordered list, where insertion and deletion are permitted at one end only.
- It is based on LIFO (Last-in First-out).
- Stack is Linear List
2. Key operation in Stack
Basic operation of stack:
- push(): method is used to push item on top of the stack.
- pop(): method is used to return from top and delete.
- top()/peek(): it returns top element (last inserted element) from the stack without removing it.
- size(): it returns number of element stored in the Stack.
- isEmpty(): it returns boolean true/false whether element is available in stack or not
3. Different Implementation of Stack
- Simple Array based implementation: in the implementation size of array is fixed. A push operation will throw exception like fullStackException when you try to push in full arraylist.
- Dynamic Array based implementation: this approach array are growable with predefined way.
- LinkedList based implementation: in this approach , push method implemented by inseting element at the begining of the list. pop() method is implemented by deleting node from the beginning.
4. Application where Stack can be Used
There are a number of application based on stack which uses extensively in every languages. Few of application where stack being used as:
- Implementing method chaining call
- Page-visit history in web browser
- Undo sequence in a text-editor
- Matching tags in HTML/XML
- Evaluation of postfix expression
- infix to postfix conversion
- Balancing symbol
Example of Stack in real life
There are number of real life example even for non-programmer,one of them as
Analysis of Performance and Limitation[table “” not found /]
Your comments/suggestions are welcome to improve this post.