#datastructuresintelugu #dsintelugu #computerpanthulu
• Stack is a linear data structure.
• Stack can be defined as a collection of homogeneous elements, where insertion and deletion operations takes place at only one end called TOP.
• The insertion operation is termed as PUSH and deletion operation is termed as POP operation.
• The PUSH and POP operations are performed at TOP of the stack.
• An element in a stack is termed as ITEM.
• The maximum number of elements that stack can accommodate is termed as SIZE of the stack.
• Stack Pointer ( SP ) always points to the top element of the stack.
• Stack follows LIFO principle. i.e. Last In First Out i.e. the element which is inserted last into the stack will be deleted first from the stack.
Diagram of a stack
Stack Operations:- We can perform mainly 3 operations on stack.
1.Push :- Inserting an element into the stack
2.Pop:- Deleting an element from the stack
3.Peep:- Displaying top most element of the stack
Representation of stack
There are two ways of representation of a stack.
1. Array representation of a stack.
2. Linked List representation of a stack.
1. Array representation of a stack.
First we have to allocate memory for array.
Starting from the first location of the memory block, items of the stack can be stored in sequential fashion.