SlideShare a Scribd company logo
Stack
Data Structure
Youtube: SL Coder
Intro to
Stack
 ADT(Abstract Data Structure).
 Based on array.
 Logically stack is linear structure.
 Data stores in top of the previous one.
Pros andCons
Advantages(Pros) are
 Insertion and deletion very quick.
 Provides LIFO(Last In First Out).
Disadvantages are
 We can not access every item in stack.
 Fixed size.
 Memory consuming.
WhereStack
are used?
 Use to Implementing recursion
 Return addresses are placed on a stack.
 For reversing string.
 Text Editors Undo/Redo feature.
 Web browser recent visited.
Complexity
 Push(insert) and pop(remove) takes constant O(1) time.
 Search takes O(n).
Operations of
Stack
 push()
 pop()
 peek()
 getSize()
 isEmpty()
 isFull()
Implementation
headerfile(Stack.h)
UsingVisual C++
 Project name is DataStructure.
 Add a class called Stack.
 In header file(Stack.h)
private:
int maxSize;
int top;
int *stack;
Implementation
Continued
header file(Stack.h)
 public:
Stack(int s);
~Stack();
void push(int value);
int pop();
int peek();
int getSize();
bool isEmpty();
bool isFull();
Implementation
Continued
cppfile(Stack.cpp)
 Stack::Stack(int s){
maxSize = s;
top = -1;
stack = new int[size];
}
 Stack::~Stack(){
delete[] stack;
}
Implementation
Continued
cppfile(Stack.cpp)
 void Stack::push(int value){
if(!isFull()){
stack[++top] = value;
}else{
cout<<“Stack is full!”<<endl;
}
}
 Int Stack::pop(){
if(!isEmpty()){
return stack[top--];
}else{
cout<<“Stack is Empty!”<<endl;
return -1;
}
}
Implementation
Continued
cppfile(Stack.cpp)
 int Stack::peek(){
if(!isEmpty()){
return stack[top];
}else{
cout<<“Stack is Empty!”<<endl;
return -1;
}
}
 int Stack::getSize(){
return maxSize;
}
Implementation
Continued
cppfile(Stack.cpp)
 b00l Stack::isEmptly(){
return top == -1;
}
 bool Stack::isFull(){
return top == maxSize - 1;
}
Implementation
Continued
mainfile(DataStructure.cpp)
Stack *numStack = new Stack(4);
numStack.push(2);
numStack.push(5);
numStack.push(6);
numStack.push(9);
numStack.peek();
numStack.pop();
numStack.peek();
Outro to
Stack • You can use Stack in any programming language.
• You can check out my Stack Implementation in java video
tutorial.
• Also Stack other videos(Stack using in projects, char data
type stack and etc.)
• And next video is Queue Data Structure.
Thanks for
Watching

More Related Content

What's hot (20)

PPTX
3.1,2,3 pushdown automata definition, moves &amp; id
Sampath Kumar S
 
PPTX
simple problem to convert NFA with epsilon to without epsilon
kanikkk
 
PPTX
stack & queue
manju rani
 
PPTX
Tower Of Hanoi
Vinit Dantkale
 
PPTX
Theory of Automata and formal languages unit 1
Abhimanyu Mishra
 
PPTX
Python operator precedence and comments
Saravanakumar viswanathan
 
PPT
Pattern matching
shravs_188
 
PPT
Top down parsing
ASHOK KUMAR REDDY
 
PPTX
Sum of subset problem.pptx
V.V.Vanniaperumal College for Women
 
PPTX
Moore Mealy Machine Conversion
Aiman Hafeez
 
PPT
Checkbox and checkbox group
myrajendra
 
PPTX
1.7. eqivalence of nfa and dfa
Sampath Kumar S
 
DOC
Ch5 answers
Hailemariam brhane
 
PPTX
Treeview listview
Amandeep Kaur
 
PPTX
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Mohammad Ilyas Malik
 
PPTX
NLP_KASHK:Finite-State Morphological Parsing
Hemantha Kulathilake
 
PPTX
push down automata
Christopher Chizoba
 
PPTX
STACKS IN DATASTRUCTURE
Archie Jamwal
 
3.1,2,3 pushdown automata definition, moves &amp; id
Sampath Kumar S
 
simple problem to convert NFA with epsilon to without epsilon
kanikkk
 
stack & queue
manju rani
 
Tower Of Hanoi
Vinit Dantkale
 
Theory of Automata and formal languages unit 1
Abhimanyu Mishra
 
Python operator precedence and comments
Saravanakumar viswanathan
 
Pattern matching
shravs_188
 
Top down parsing
ASHOK KUMAR REDDY
 
Sum of subset problem.pptx
V.V.Vanniaperumal College for Women
 
Moore Mealy Machine Conversion
Aiman Hafeez
 
Checkbox and checkbox group
myrajendra
 
1.7. eqivalence of nfa and dfa
Sampath Kumar S
 
Ch5 answers
Hailemariam brhane
 
Treeview listview
Amandeep Kaur
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Mohammad Ilyas Malik
 
NLP_KASHK:Finite-State Morphological Parsing
Hemantha Kulathilake
 
push down automata
Christopher Chizoba
 
STACKS IN DATASTRUCTURE
Archie Jamwal
 

Viewers also liked (20)

PPTX
Data structure Stack
Praveen Vishwakarma
 
PPSX
Data Structure (Stack)
Adam Mukharil Bachtiar
 
PPT
Stack Data Structure & It's Application
Tech_MX
 
PPT
data structure, stack, stack data structure
pcnmtutorials
 
PPT
Stack Data Structure V1.0
Zidny Nafan
 
PPTX
Stack data structure
Tech_MX
 
PPT
Stacks
Temperory mukesh
 
PPT
03 stacks and_queues_using_arrays
tameemyousaf
 
PPT
Stack a Data Structure
ForwardBlog Enewzletter
 
PDF
Applications of stack
eShikshak
 
PPTX
Tree in data structure
ghhgj jhgh
 
PPT
Queue data structure
anooppjoseph
 
PPTX
Trees data structure
Sumit Gupta
 
PPSX
Stack
Seema Sharma
 
PPT
Queue Data Structure
Zidny Nafan
 
PDF
Queue as data_structure
eShikshak
 
PDF
Tree and binary tree
Zaid Shabbir
 
PPTX
Linked list
akshat360
 
PPTX
Data structure and its types
Navtar Sidhu Brar
 
Data structure Stack
Praveen Vishwakarma
 
Data Structure (Stack)
Adam Mukharil Bachtiar
 
Stack Data Structure & It's Application
Tech_MX
 
data structure, stack, stack data structure
pcnmtutorials
 
Stack Data Structure V1.0
Zidny Nafan
 
Stack data structure
Tech_MX
 
03 stacks and_queues_using_arrays
tameemyousaf
 
Stack a Data Structure
ForwardBlog Enewzletter
 
Applications of stack
eShikshak
 
Tree in data structure
ghhgj jhgh
 
Queue data structure
anooppjoseph
 
Trees data structure
Sumit Gupta
 
Queue Data Structure
Zidny Nafan
 
Queue as data_structure
eShikshak
 
Tree and binary tree
Zaid Shabbir
 
Linked list
akshat360
 
Data structure and its types
Navtar Sidhu Brar
 
Ad

Similar to Stack Data structure (20)

PPTX
Sour Pickles
SensePost
 
PPTX
Ontopia tutorial
Lars Marius Garshol
 
PPT
Stacks in algorithems & data structure
faran nawaz
 
PPTX
Exploring SharePoint with F#
Talbott Crowell
 
PPT
JDK1.7 features
india_mani
 
PPT
Data Strcture and Algorithms - Destailed Analysis of Stacks
donotreply20
 
PPT
Java concurrency
ducquoc_vn
 
PPTX
Advanced data structures slide 2 2+
jomerson remorosa
 
PPT
Minute Of Eclipse Papyrus Pre-Committing
BENOIS Jérôme
 
PDF
Data-structures7 class xii ashdshd hfuidshfkjhjsa ioh
KirtikaTomar1
 
PDF
Short Lightening Talk
Ikenna Okpala
 
PDF
Ikenna Okpala: London Java Community: Wicket and Scala - 27/07/2010.
Skills Matter
 
PPTX
CD3291 2.5 stack.pptx
mareeswari15
 
PDF
T3chFest 2016 - The polyglot programmer
David Muñoz Díaz
 
PDF
BP107: Ten Lines Or Less: Interesting Things You Can Do In Java With Minimal ...
panagenda
 
PDF
10 Lines or Less; Interesting Things You Can Do In Java With Minimal Code
Kathy Brown
 
PPTX
Data structure , stack , queue
Rajkiran Nadar
 
PDF
Design patterns
Anas Alpure
 
PPTX
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
PPTX
Hammock, a Good Place to Rest
Stratoscale
 
Sour Pickles
SensePost
 
Ontopia tutorial
Lars Marius Garshol
 
Stacks in algorithems & data structure
faran nawaz
 
Exploring SharePoint with F#
Talbott Crowell
 
JDK1.7 features
india_mani
 
Data Strcture and Algorithms - Destailed Analysis of Stacks
donotreply20
 
Java concurrency
ducquoc_vn
 
Advanced data structures slide 2 2+
jomerson remorosa
 
Minute Of Eclipse Papyrus Pre-Committing
BENOIS Jérôme
 
Data-structures7 class xii ashdshd hfuidshfkjhjsa ioh
KirtikaTomar1
 
Short Lightening Talk
Ikenna Okpala
 
Ikenna Okpala: London Java Community: Wicket and Scala - 27/07/2010.
Skills Matter
 
CD3291 2.5 stack.pptx
mareeswari15
 
T3chFest 2016 - The polyglot programmer
David Muñoz Díaz
 
BP107: Ten Lines Or Less: Interesting Things You Can Do In Java With Minimal ...
panagenda
 
10 Lines or Less; Interesting Things You Can Do In Java With Minimal Code
Kathy Brown
 
Data structure , stack , queue
Rajkiran Nadar
 
Design patterns
Anas Alpure
 
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
Hammock, a Good Place to Rest
Stratoscale
 
Ad

Recently uploaded (20)

PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
community health nursing question paper 2.pdf
Prince kumar
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 

Stack Data structure