A stack is a linear data structure which can be implemented either using an array or a linked list. The elements in a stack are added and removed only from one end, which is called top. Hence, a stack is called a LIFO (Last In First Out) data structure as the element that was inserted last is the first one to be taken out.
- Push Operation :- The push operation is used to insert an element into the stack. Before, inserting the value, we must first check if TOP=MAX-1, because if this is the case then it means the stack is full and no more insertions can further be done. If an attempt is made to insert a value in a stack that is already full, an OVERFLOW message is printed.
- Pop Operation :- The pop operation is used to delete the topmost element from the stack. Before, deleting the value, we must first check if TOP=NULL, because if this is the case then it means the stack is empty so no more deletion can further be done. If an attempt is made to delete a value from a stack that is already empty, an UNDERFLOW message is printed.