SlideShare a Scribd company logo
2
Most read
7
Most read
14
Most read
STACK DATA STRUCTURE
Roopak Bhama
(MCA/25003/18)
SP-2019
BIRLA INSTITUTE OF TECHNOLOGY
MESRA, JAIPUR CAMPUS
WHAT IS A DATA STRUCTURE
• Data Structure is a way to store and organize data so that
it can be used efficiently.
• It is a special format for organizing and storing data.
• Data Structures
• Linear Structure
• Linked List
• Stack
• Queue
• Non Linear Structure
• Graph
• Tree
ABSTRACT DATA TYPES
• To simplify process of problem solving, we combine
data structure with their operations and call this
Abstract Data Types (ADT)
• It consists of 2 parts
• Declaration of Data
• Declaration of Operations
WHAT IS STACK
• A stack is an ordered list
in which insertion and
deletion are done at one
end, called top.
• The last element inserted
is the first one to be
deleted.
• Hence it is called Last In
First Out(LIFO) or First In
Last Out(FILO).
STACK ADT
Stack
Main Stack
Operations
push (int data)
int pop()
Auxiliary Stack
Operations
int top()
int size()
int isEmpty()
int isFull()
STACK OPERATIONS
Operation Description
push(int data) inserts data into stack
int pop() removes and returns last inserted
element
int top() returns last inserted element
int size() returns number of elements in stack
int isEmpty() indicate if any element is stored or not
int isFull() indicates if stack is full or not
STACK APPLICATIONS
• Balancing of Symbols
• Infix to Postfix conversion
• Evaluation of postfix expression
• Implementing function calls
• History of a web browser
• Undo Sequence
• Tree Traversal
WORKING
TOP = 0
MAX = 5
10
TOP = 1
MAX = 5
CREATE STACK
SIZE 5
PUSH(10)
WORKING
10
20
TOP = 2
MAX = 5
10
20
30
TOP = 3
MAX = 5
PUSH(30)PUSH(20)
WORKING
10
20
30
40
TOP = 4
MAX = 5
10
20
30
TOP = 3
MAX = 5
POP()PUSH(40)
WORKING
10
20
TOP = 2
MAX = 5
10
TOP = 1
MAX = 5
POP()POP()
WORKING
TOP = 0
MAX = 5
FULLSTACK()EMPTYSTACK()
10
20
30
40
50
TOP = 4
MAX = 5
IMPLEMENTATION BY ARRAY
• Advantages
• Best Performance
• Disadvantages
• Fixed Size
• Basic Implementation
• Initially Empty Array
• Field to record where next data is placed
• if array is full, push(item) else return false
• if array is empty, pop() return item on top else NULL
IMPLEMENTATION BY ARRAY
• CREATING STRUCTURE
• struct ArrayStruct{
• int top; //Keep track of top Element
• int capacity; //capacity of the stack
• int *array; //pointer to address of first index
• }
• Space Complexity (for n operations)– O(n)
IMPLEMENTATION BY ARRAY
• isEmpty(){
• return (S->top == -1);
• }
• Time Complexity
• O(1)
• isFull(){
• return(S->top==S->capacity-
1);
• }
• Time Complexity
• O(1)
IMPLEMENTATION BY ARRAY
• void push(struct Array *S,int
data){
• if(isFull(S))
• cout<<“FULL”;
• else
• S->array[++S->top]=data;
• }
• Time Complexity
• O(1)
• int pop(struct Array *S){
• if(isEmpty(S)){
• cout<<“EMPTY”;
• return;}
• else
• return (S->array[S->top]);
• }
• Time Complexity
• O(1)
LINKED LIST IMPLEMENTATION
• Advantages
• Always constant time to push and pop
• can grow to an infinite size
• Disadvantages
• can grow to infinite size
• common case is slowest of all
• Basic Implementation
• Initially Empty List
• push() add item on top
• pop() removes item on top
LINKED LIST IMPLEMENTATION
• void push(struct node **top,int d){
• struct node *temp;
• temp->data=d;
• temp->link=(*top);
• *temp = temp;
• }
• Time Complexity
• O(1)
• void pop(struct node **top){
• struct node *temp; int i;
• temp=(*top);
• i=temp->data;
• *top = (*top)->link;
• return i;
• }
• Time Complexity
• O(1)
USE OF STACK
EVALUATING POSTFIX = 123*+5-
Stack
Expressio
n
STEP 1
2
3
1
Stack
Expressio
n
STEP 2
USE OF STACK
EVALUATING POSTFIX = 123*+5-
1
Stack
Expressio
n
2*3=6
STEP 3
6
1
Stack
Expressio
n
STEP 4
USE OF STACK
EVALUATING POSTFIX = 123*+5-
Stack
Expressio
n
1+6=7
STEP 5
7
Stack
Expressio
n
STEP 6
USE OF STACK
EVALUATING POSTFIX = 123*+5-
5
7
Stack
Expressio
n
STEP 7
Stack
Expressio
n
7-5=2
STEP 8
USE OF STACK
EVALUATING POSTFIX = 123*+5-
2
Stack
Expressio
n
STEP 9
123*+5-
RESULT
POSTFIX STRING
2
REFERENCES
• Data Structures and Algorithms, Narsimha
Karumanchi
• https://www.geeksforgeeks.org/stack-data-structure/
• https://www.geeksforgeeks.org/tag/data-structures-
stack/

More Related Content

What's hot (20)

PPT
Stack a Data Structure
ForwardBlog Enewzletter
 
PPTX
Data structure & its types
Rameesha Sadaqat
 
PPTX
Programming in c Arrays
janani thirupathi
 
PPTX
Conversion of Infix to Prefix and Postfix with Stack
sahil kumar
 
PPTX
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
PPTX
Linked List
RaaviKapoor
 
PPTX
Array ppt
Kaushal Mehta
 
PPTX
Data structure and its types
Navtar Sidhu Brar
 
PPSX
Data Structure (Queue)
Adam Mukharil Bachtiar
 
PPTX
The Stack And Recursion
Ashim Lamichhane
 
PDF
sparse matrix in data structure
MAHALAKSHMI P
 
PPTX
Stack of Data structure
Sheikh Monirul Hasan
 
PPTX
Sparse matrix and its representation data structure
Vardhil Patel
 
PPT
stack presentation
Shivalik college of engineering
 
PPTX
Linked list
KalaivaniKS1
 
PPTX
Unit 4 python -list methods
narmadhakin
 
PPTX
Data structure by Digvijay
Digvijay Singh Karakoti
 
PPT
Stacks
sweta dargad
 
PPTX
Infix to postfix conversion
Then Murugeshwari
 
PPTX
Pointer in c
lavanya marichamy
 
Stack a Data Structure
ForwardBlog Enewzletter
 
Data structure & its types
Rameesha Sadaqat
 
Programming in c Arrays
janani thirupathi
 
Conversion of Infix to Prefix and Postfix with Stack
sahil kumar
 
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Linked List
RaaviKapoor
 
Array ppt
Kaushal Mehta
 
Data structure and its types
Navtar Sidhu Brar
 
Data Structure (Queue)
Adam Mukharil Bachtiar
 
The Stack And Recursion
Ashim Lamichhane
 
sparse matrix in data structure
MAHALAKSHMI P
 
Stack of Data structure
Sheikh Monirul Hasan
 
Sparse matrix and its representation data structure
Vardhil Patel
 
Linked list
KalaivaniKS1
 
Unit 4 python -list methods
narmadhakin
 
Data structure by Digvijay
Digvijay Singh Karakoti
 
Stacks
sweta dargad
 
Infix to postfix conversion
Then Murugeshwari
 
Pointer in c
lavanya marichamy
 

Similar to Stack data structure in Data Structure using C (20)

PPTX
stack_operationss_documentation_file.ppt
l228296
 
PPTX
Data Structures and Agorithm: DS 06 Stack.pptx
RashidFaridChishti
 
DOCX
Ds
Acad
 
PDF
Stack
maamir farooq
 
PPTX
chapter three ppt.pptx
selemonGamo
 
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Balwant Gorad
 
PPTX
My lecture stack_queue_operation
Senthil Kumar
 
PPT
Lecture5
Muhammad Zubair
 
PPTX
Abscddnddmdkwkkstack implementation.pptx
zainshahid3040
 
PPTX
Stack and its applications
Ahsan Mansiv
 
PDF
Chapter 4 stack
jadhav_priti
 
PDF
DS UNIT 1.pdf
SeethaDinesh
 
PDF
DS UNIT 1.pdf
SeethaDinesh
 
PPTX
Stack Data Structure
Rabin BK
 
PPTX
DATA STRUCTURE AND COMPUTER ALGORITHMS LECTURE 2
emathemathematics
 
PPTX
Data structure , stack , queue
Rajkiran Nadar
 
PDF
Data structure.pdf
piyushagarwal279293
 
PDF
Chapter 5 Stack and Queue.pdf
GirT2
 
PPTX
Stack in Sata Structure
Muhazzab Chouhadry
 
PDF
04 stacks
Rajan Gautam
 
stack_operationss_documentation_file.ppt
l228296
 
Data Structures and Agorithm: DS 06 Stack.pptx
RashidFaridChishti
 
Ds
Acad
 
chapter three ppt.pptx
selemonGamo
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Balwant Gorad
 
My lecture stack_queue_operation
Senthil Kumar
 
Lecture5
Muhammad Zubair
 
Abscddnddmdkwkkstack implementation.pptx
zainshahid3040
 
Stack and its applications
Ahsan Mansiv
 
Chapter 4 stack
jadhav_priti
 
DS UNIT 1.pdf
SeethaDinesh
 
DS UNIT 1.pdf
SeethaDinesh
 
Stack Data Structure
Rabin BK
 
DATA STRUCTURE AND COMPUTER ALGORITHMS LECTURE 2
emathemathematics
 
Data structure , stack , queue
Rajkiran Nadar
 
Data structure.pdf
piyushagarwal279293
 
Chapter 5 Stack and Queue.pdf
GirT2
 
Stack in Sata Structure
Muhazzab Chouhadry
 
04 stacks
Rajan Gautam
 
Ad

More from Meghaj Mallick (20)

PPT
24 partial-orderings
Meghaj Mallick
 
PPTX
PORTFOLIO BY USING HTML & CSS
Meghaj Mallick
 
PPTX
Introduction to Software Testing
Meghaj Mallick
 
PPTX
Introduction to System Programming
Meghaj Mallick
 
PPTX
MACRO ASSEBLER
Meghaj Mallick
 
PPTX
Icons, Image & Multimedia
Meghaj Mallick
 
PPTX
Project Tracking & SPC
Meghaj Mallick
 
PPTX
Peephole Optimization
Meghaj Mallick
 
PPTX
Routing in MANET
Meghaj Mallick
 
PPTX
Macro assembler
Meghaj Mallick
 
PPTX
Architecture and security in Vanet PPT
Meghaj Mallick
 
PPTX
Design Model & User Interface Design in Software Engineering
Meghaj Mallick
 
PPTX
Text Mining of Twitter in Data Mining
Meghaj Mallick
 
PPTX
DFS & BFS in Computer Algorithm
Meghaj Mallick
 
PPTX
Software Development Method
Meghaj Mallick
 
PPTX
Secant method in Numerical & Statistical Method
Meghaj Mallick
 
PPTX
Motivation in Organization
Meghaj Mallick
 
PPTX
Communication Skill
Meghaj Mallick
 
PPT
Partial-Orderings in Discrete Mathematics
Meghaj Mallick
 
PPTX
Hashing In Data Structure
Meghaj Mallick
 
24 partial-orderings
Meghaj Mallick
 
PORTFOLIO BY USING HTML & CSS
Meghaj Mallick
 
Introduction to Software Testing
Meghaj Mallick
 
Introduction to System Programming
Meghaj Mallick
 
MACRO ASSEBLER
Meghaj Mallick
 
Icons, Image & Multimedia
Meghaj Mallick
 
Project Tracking & SPC
Meghaj Mallick
 
Peephole Optimization
Meghaj Mallick
 
Routing in MANET
Meghaj Mallick
 
Macro assembler
Meghaj Mallick
 
Architecture and security in Vanet PPT
Meghaj Mallick
 
Design Model & User Interface Design in Software Engineering
Meghaj Mallick
 
Text Mining of Twitter in Data Mining
Meghaj Mallick
 
DFS & BFS in Computer Algorithm
Meghaj Mallick
 
Software Development Method
Meghaj Mallick
 
Secant method in Numerical & Statistical Method
Meghaj Mallick
 
Motivation in Organization
Meghaj Mallick
 
Communication Skill
Meghaj Mallick
 
Partial-Orderings in Discrete Mathematics
Meghaj Mallick
 
Hashing In Data Structure
Meghaj Mallick
 
Ad

Recently uploaded (16)

PPTX
Food_and_Drink_Bahasa_Inggris_Kelas_5.pptx
debbystevani36
 
PDF
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
PPTX
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
PDF
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
PPTX
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
PPTX
AI presentation for everyone in every fields
dodinhkhai1
 
PPTX
some leadership theories MBA management.pptx
rkseo19
 
PDF
Generalization predition MOOCs - Conference presentation - eMOOCs 2025
pmmorenom01
 
PPTX
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
PPTX
2025-07-06 Abraham 06 (shared slides).pptx
Dale Wells
 
PPTX
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
PPTX
presentation on legal and regulatory action
raoharsh4122001
 
PPTX
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
PDF
Cloud Computing Service Availability.pdf
chakrirocky1
 
PDF
The Family Secret (essence of loveliness)
Favour Biodun
 
PPTX
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
Food_and_Drink_Bahasa_Inggris_Kelas_5.pptx
debbystevani36
 
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
AI presentation for everyone in every fields
dodinhkhai1
 
some leadership theories MBA management.pptx
rkseo19
 
Generalization predition MOOCs - Conference presentation - eMOOCs 2025
pmmorenom01
 
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
2025-07-06 Abraham 06 (shared slides).pptx
Dale Wells
 
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
presentation on legal and regulatory action
raoharsh4122001
 
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
Cloud Computing Service Availability.pdf
chakrirocky1
 
The Family Secret (essence of loveliness)
Favour Biodun
 
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 

Stack data structure in Data Structure using C

  • 1. STACK DATA STRUCTURE Roopak Bhama (MCA/25003/18) SP-2019 BIRLA INSTITUTE OF TECHNOLOGY MESRA, JAIPUR CAMPUS
  • 2. WHAT IS A DATA STRUCTURE • Data Structure is a way to store and organize data so that it can be used efficiently. • It is a special format for organizing and storing data. • Data Structures • Linear Structure • Linked List • Stack • Queue • Non Linear Structure • Graph • Tree
  • 3. ABSTRACT DATA TYPES • To simplify process of problem solving, we combine data structure with their operations and call this Abstract Data Types (ADT) • It consists of 2 parts • Declaration of Data • Declaration of Operations
  • 4. WHAT IS STACK • A stack is an ordered list in which insertion and deletion are done at one end, called top. • The last element inserted is the first one to be deleted. • Hence it is called Last In First Out(LIFO) or First In Last Out(FILO).
  • 5. STACK ADT Stack Main Stack Operations push (int data) int pop() Auxiliary Stack Operations int top() int size() int isEmpty() int isFull()
  • 6. STACK OPERATIONS Operation Description push(int data) inserts data into stack int pop() removes and returns last inserted element int top() returns last inserted element int size() returns number of elements in stack int isEmpty() indicate if any element is stored or not int isFull() indicates if stack is full or not
  • 7. STACK APPLICATIONS • Balancing of Symbols • Infix to Postfix conversion • Evaluation of postfix expression • Implementing function calls • History of a web browser • Undo Sequence • Tree Traversal
  • 8. WORKING TOP = 0 MAX = 5 10 TOP = 1 MAX = 5 CREATE STACK SIZE 5 PUSH(10)
  • 9. WORKING 10 20 TOP = 2 MAX = 5 10 20 30 TOP = 3 MAX = 5 PUSH(30)PUSH(20)
  • 10. WORKING 10 20 30 40 TOP = 4 MAX = 5 10 20 30 TOP = 3 MAX = 5 POP()PUSH(40)
  • 11. WORKING 10 20 TOP = 2 MAX = 5 10 TOP = 1 MAX = 5 POP()POP()
  • 12. WORKING TOP = 0 MAX = 5 FULLSTACK()EMPTYSTACK() 10 20 30 40 50 TOP = 4 MAX = 5
  • 13. IMPLEMENTATION BY ARRAY • Advantages • Best Performance • Disadvantages • Fixed Size • Basic Implementation • Initially Empty Array • Field to record where next data is placed • if array is full, push(item) else return false • if array is empty, pop() return item on top else NULL
  • 14. IMPLEMENTATION BY ARRAY • CREATING STRUCTURE • struct ArrayStruct{ • int top; //Keep track of top Element • int capacity; //capacity of the stack • int *array; //pointer to address of first index • } • Space Complexity (for n operations)– O(n)
  • 15. IMPLEMENTATION BY ARRAY • isEmpty(){ • return (S->top == -1); • } • Time Complexity • O(1) • isFull(){ • return(S->top==S->capacity- 1); • } • Time Complexity • O(1)
  • 16. IMPLEMENTATION BY ARRAY • void push(struct Array *S,int data){ • if(isFull(S)) • cout<<“FULL”; • else • S->array[++S->top]=data; • } • Time Complexity • O(1) • int pop(struct Array *S){ • if(isEmpty(S)){ • cout<<“EMPTY”; • return;} • else • return (S->array[S->top]); • } • Time Complexity • O(1)
  • 17. LINKED LIST IMPLEMENTATION • Advantages • Always constant time to push and pop • can grow to an infinite size • Disadvantages • can grow to infinite size • common case is slowest of all • Basic Implementation • Initially Empty List • push() add item on top • pop() removes item on top
  • 18. LINKED LIST IMPLEMENTATION • void push(struct node **top,int d){ • struct node *temp; • temp->data=d; • temp->link=(*top); • *temp = temp; • } • Time Complexity • O(1) • void pop(struct node **top){ • struct node *temp; int i; • temp=(*top); • i=temp->data; • *top = (*top)->link; • return i; • } • Time Complexity • O(1)
  • 19. USE OF STACK EVALUATING POSTFIX = 123*+5- Stack Expressio n STEP 1 2 3 1 Stack Expressio n STEP 2
  • 20. USE OF STACK EVALUATING POSTFIX = 123*+5- 1 Stack Expressio n 2*3=6 STEP 3 6 1 Stack Expressio n STEP 4
  • 21. USE OF STACK EVALUATING POSTFIX = 123*+5- Stack Expressio n 1+6=7 STEP 5 7 Stack Expressio n STEP 6
  • 22. USE OF STACK EVALUATING POSTFIX = 123*+5- 5 7 Stack Expressio n STEP 7 Stack Expressio n 7-5=2 STEP 8
  • 23. USE OF STACK EVALUATING POSTFIX = 123*+5- 2 Stack Expressio n STEP 9 123*+5- RESULT POSTFIX STRING 2
  • 24. REFERENCES • Data Structures and Algorithms, Narsimha Karumanchi • https://www.geeksforgeeks.org/stack-data-structure/ • https://www.geeksforgeeks.org/tag/data-structures- stack/