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 ?
0 1 2 3 4
In a stack all operation like
insertion and deletion are
performed at only one end
called Top
What is a STACK ?
In a stack all operation like
insertion and deletion are
performed at only one end
called Top
1
2
3
4
0
Insertion Deletion
Top
Operations on STACK ?
Insertion
Deletion
Displaying
Creation
Operations on STACK ?
Insertion
Deletion
Displaying
Creation #define SIZE 5
int stack[SIZE];
1
2
3
4
0
stack
Operations on STACK ?
Insertion
Deletion
Displaying
Creation
void push(element){
if(Stack is full)
{
printf(“FULL!!!”);
}
else
{
Top++;
stack[Top] = element;
}
}
1
2
3
4
0
stack
Insertion operation is called as “push”
Operations on STACK ?
Insertion
Deletion
Displaying
Creation
int pop( ){
if(Stack is Empty)
{
printf(“EMPTY!!!”);
return Top;
}
else
{
deleted = stack[Top];
Top--;
return deleted;
}
}
1
2
3
4
0
stack
Deletion operation is called as “pop”
Operations on STACK ?
Insertion
Deletion
Displaying
Creation
void display( ){
if(Stack is Empty)
{
printf(“EMPTY!!!”);
}
else
{
for(i=Top; i>-1; i--)
printf(“%dn”,stack[i]);
}
}
1
2
3
4
0
stack

Stack-data-structure.ppsxErwewwwrrterewewew

  • 1.
  • 2.
    What is aSTACK ? 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
  • 3.
    What is aSTACK ? 0 1 2 3 4 In a stack all operation like insertion and deletion are performed at only one end called Top
  • 4.
    What is aSTACK ? In a stack all operation like insertion and deletion are performed at only one end called Top 1 2 3 4 0 Insertion Deletion Top
  • 5.
    Operations on STACK? Insertion Deletion Displaying Creation
  • 6.
    Operations on STACK? Insertion Deletion Displaying Creation #define SIZE 5 int stack[SIZE]; 1 2 3 4 0 stack
  • 7.
    Operations on STACK? Insertion Deletion Displaying Creation void push(element){ if(Stack is full) { printf(“FULL!!!”); } else { Top++; stack[Top] = element; } } 1 2 3 4 0 stack Insertion operation is called as “push”
  • 8.
    Operations on STACK? Insertion Deletion Displaying Creation int pop( ){ if(Stack is Empty) { printf(“EMPTY!!!”); return Top; } else { deleted = stack[Top]; Top--; return deleted; } } 1 2 3 4 0 stack Deletion operation is called as “pop”
  • 9.
    Operations on STACK? Insertion Deletion Displaying Creation void display( ){ if(Stack is Empty) { printf(“EMPTY!!!”); } else { for(i=Top; i>-1; i--) printf(“%dn”,stack[i]); } } 1 2 3 4 0 stack