A stack is a linear data structure, collection of items of the same type.
Stack follows the Last In First Out (LIFO) fashion wherein the last element entered is the first one to be popped out.
In stacks, the insertion and deletion of elements happen only at one endpoint of it.
1. Operations performed on Stacks
The following are the basic operations served by the Stacks.
Push: This function adds an element to the top of the Stack.
Pop: This function removes the topmost element from the stack.
IsEmpty: Checks whether the stack is empty.
IsFull: Checks whether the stack is full.
Top: Displays the topmost element of the stack.
Applications of Stack
As soon as the compiler encounters a function call, it gets pushed into the stack.
In the case of nested functions, the inner functions get executed before the outer functions. This is totally managed by stacks.
The Stack is used to solve a few of the general problems like:
1.Tower of Hanoi
2.N queens problem
3.Infix to prefix conversion