Stack Data Structure

You might also like

Download as ppsx, pdf, or txt
Download as ppsx, pdf, or txt
You are on page 1of 9

STACK

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.

A stack is a ordered list of elements of same data type

A stack is a Linear list


What is a STACK ?

In a stack all operation like


insertion and deletion are
performed at only one end 0 1 2 3 4
called Top
What is a STACK ?
Insertion Deletion

In a stack all operation like


4 Top
insertion and deletion are
performed at only one end 3
called Top 2

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”

4
Creation
void push(element){
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

You might also like