A stack is a simple data structure used for storing data (similar to Linked Lists). In stack the order in which the data arrives is important. The pile of plates of a cafeteria is a good example of a stack. The plates are added to the stack as they are cleaned. They are placed on the top. When a plate is required it is taken from the top of the stack. The first plate placed on the stack is the last one to be used.
A Stack is an ordered list in which insertion and deletion are done at one end, called as the top. The last element inserted is the first one to be deleted. Hence, it is called Last In First Out (LIFO) or First In Last Out (FILO) list.
Stack ADT
Main stack operations:
- void push (int data): Inserts data onto a stack.
- int pop(): Removes and returns the last inserted element from the stack.
Applications:
- Balancing of symbols
- Infix-to-postfix conversion
- Evaluation of postfix expression
- Implementing function calls (including recursion)
- Finding of spans (finding spans in stock markets)
- Page-visited history in a Web Browser (Back Buttons)
- Undo sequence in a text editor
- Matching Tags in HTML and XML
source: Data Structures and Algorithms Made Easy in Java ( By Narasimha Karumanchi )



