Stack Data Structure - PPSX
Stack Data Structure - PPSX
Data Structure
www.btechsmartclass.com
What is a STACK ?
A stack is a container of elements that are inserted and
removed according to the last-in first-out (LIFO) principle.
0
Operations on STACK ?
Creation
Insertion
Deletion
Displaying
Operations on STACK ?
4
Creation #define SIZE 5
int stack[SIZE];
3
Insertion
2
Deletion
1
Displaying
0
stack
Operations on STACK ?
Insertion operation is called as “push”
void push(element){ 4
Creation if(Stack is full)
{ 3
Insertion printf(“FULL!!!”);
} 2
Deletion else
{ 1
Displaying Top++;
stack[Top] = element; 0
} stack
}
Operations on STACK ?
Deletion operation is called as “pop”
int pop( ){ 4
Creation if(Stack is Empty)
{
3
Insertion printf(“EMPTY!!!”);
return Top;
} 2
Deletion else
{ 1
Displaying deleted = stack[Top];
Top--; 0
return deleted;
} stack
}
Operations on STACK ?
void display( ){ 4
Creation if(Stack is Empty)
{
3
Insertion }
printf(“EMPTY!!!”);
else 2
Deletion {
for(i=Top; i>-1; i--) 1
Displaying printf(“%d\n”,stack[i]);
} 0
}
stack