A stack is an ordered list in which insertion and deletion are done at one end, called top. The last element inserted is the first one to be deleted. Hence it is called LIFO(Last In First Out) or First In Last Out(FILO) list.
To understand it in a better way, we can take this example of pile of plates of a cafeteria, 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 satck os the last one to be used.
- Push: When as elemnt is inserted in stack, the operation is called Push.
- Pop: When an element is deleted from stack, the operation is called Pop.
push 3 Pop: (Element after performing pop: 3)
3
12 12 12
43 43 43
33 33 33
34 34 34
Direct applications:
- Balancing of symbols.
- Infix to postfix conversion.
- Evaluation of postfix Expression.
- Implementing the function calls(including recursion)
- Page visited history in web browser.
- Undo sequence in a text editor.
- Matching tags in HTML and XML.
Indirect Applications:
- Auxiliary data structure for other algorithms. (Example: Tree traversal algorithm)
- Component of other data structures (Example: Stimulating queues)