0% found this document useful (0 votes)
39 views

Stack Data Structure - PPSX

A stack is a linear data structure that follows the LIFO (last-in, first-out) principle. Elements are inserted and removed from only one end, called the top. The main operations on a stack are push to insert, pop to remove, and display to show all elements. Push adds an element to the top, pop removes from the top, and display prints the stack contents from top to bottom.

Uploaded by

josephravi
Copyright
© © All Rights Reserved
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Stack Data Structure - PPSX

A stack is a linear data structure that follows the LIFO (last-in, first-out) principle. Elements are inserted and removed from only one end, called the top. The main operations on a stack are push to insert, pop to remove, and display to show all elements. Push adds an element to the top, pop removes from the top, and display prints the stack contents from top to bottom.

Uploaded by

josephravi
Copyright
© © All Rights Reserved
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 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”

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

You might also like