Stack Using Array
Stack is an LIFO (Last In First Out) data structure.
Stack is a linear data structure where insertion and deletion operations are performed from one end called TOP. A TOP is a pointer which points to the top element- the element which entered last in the stack.
Stack can be implemented with an array and a linked list. Here, We will see the implementation of stack using array in C with basic operations on stack.
Basic Operations on Stack
- PUSH
- POP
Insertion of element in the stack is called as PUSH and Deletion of element from the stack is called POP operation.
Algorithm:
PUSH(Stack, N, Item)
This algorithm will insert Item at top to Stack having size N. Here initial index for stack is 0.
if TOP >= N - 1 then "Overflow" else TOP = TOP + 1 Stack[TOP] = Item

PUSH Operation on Stack
POP(Stack, N)
This algorithm will delete the top element from the Stack having size N. Here initial index for stack is 0.
if TOP = -1 then "Underflow" else Stack[TOP] = NULL TOP = TOP - 1

POP Operation on Stack