SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Stacks
Stack is an abstract data type with a bounded(predefined) capacity. It is a simple data structure that
allows adding and removing elements in a particular order. Every time an element is added, it goes
on the top of the stack, the only element that can be removed is the element that was at the top of
the stack, just like a pile of objects.
Basic features of Stack
1. Stack is an ordered list of similar data type.
2. Stack is a LIFO structure. (Last in First out).
3. push() function is used to insert new elements into the Stack and pop() is used to delete an
element from the stack. Both insertion and deletion are allowed at only one end of Stack
called Top.
4. Stack is said to be in Overflow state when it is completely full and is said to be
in Underflow state if it is completely empty.
Applications of Stack
The simplest application of a stack is to reverse a word. You push a given word to stack - letter by
letter - and then pop letters from the stack.
There are other uses also like : Parsing, Expression Conversion(Infixto Postfix, Postfix to Prefix
etc) and many more.
Implementation of Stack
Stack can be easily implemented using an Array or a Linked List. Arrays are quick, but are limited in
size and Linked List requires overhead to allocate, link, unlink, and deallocate, but is not limited in
size. Here we will implement Stack using array.
/* Below program is written in C++ language */
Class Stack
{
int top;
public:
int a[10]; //Maximum size of Stack
Stack()
{
top = -1;
}
};
void Stack::push(int x)
{
if( top >= 10)
{
cout << "Stack Overflow";
}
else
{
a[++top] = x;
cout << "Element Inserted";
}
}
int Stack::pop()
{
if(top < 0)
{
cout << "Stack Underflow";
return 0;
}
else
{
int d = a[top--];
return d;
}
}
void Stack::isEmpty()
{
if(top < 0)
{
cout << "Stack is empty";
}
else
{
cout << "Stack is not empty";
}
}
Position of Top Status of Stack
-1 Stack is Empty
0 Only one element in Stack
N-1 Stack is Full
N Overflow state of Stack
Analysis of Stacks
Below mentioned are the time complexities for various operations that can be performed on the
Stack data structure.
 Push Operation : O(1)
 Pop Operation : O(1)
 Top Operation : O(1)
 Search Operation : O(n)

More Related Content

What's hot (20)

PDF
Data Structures Chapter-4
priyavanimurugarajan
 
PDF
Applications of stack
eShikshak
 
PPTX
2. Array in Data Structure
Mandeep Singh
 
PPTX
Transposition cipher techniques
SHUBHA CHATURVEDI
 
PDF
Infix to postfix expression in ds
Rohini Mahajan
 
PDF
Data Structures (BE)
PRABHAHARAN429
 
PPT
Stacks & Queues By Ms. Niti Arora
kulachihansraj
 
PPT
Stack
srihariyenduri
 
PPT
Heap tree
Shankar Bishnoi
 
PPTX
And or graph
Ali A Jalil
 
PDF
Binary search tree operations
Kamran Zafar
 
PPTX
Array implementation and linked list as datat structure
Tushar Aneyrao
 
PPTX
QUEUE.pptx
MattFlordeliza1
 
PPTX
Deletion from single way linked list and search
Estiak Khan
 
PPTX
Python list
ArchanaBhumkar
 
PPTX
Linked List
Ashim Lamichhane
 
PPTX
Secure Hash Algorithm (SHA)
ShahDhruv21
 
PPTX
Tower Of Hanoi -A MatheMatical PuZzle
purvanahar
 
PPTX
Unit 4 queue
Dabbal Singh Mahara
 
Data Structures Chapter-4
priyavanimurugarajan
 
Applications of stack
eShikshak
 
2. Array in Data Structure
Mandeep Singh
 
Transposition cipher techniques
SHUBHA CHATURVEDI
 
Infix to postfix expression in ds
Rohini Mahajan
 
Data Structures (BE)
PRABHAHARAN429
 
Stacks & Queues By Ms. Niti Arora
kulachihansraj
 
Heap tree
Shankar Bishnoi
 
And or graph
Ali A Jalil
 
Binary search tree operations
Kamran Zafar
 
Array implementation and linked list as datat structure
Tushar Aneyrao
 
QUEUE.pptx
MattFlordeliza1
 
Deletion from single way linked list and search
Estiak Khan
 
Python list
ArchanaBhumkar
 
Linked List
Ashim Lamichhane
 
Secure Hash Algorithm (SHA)
ShahDhruv21
 
Tower Of Hanoi -A MatheMatical PuZzle
purvanahar
 
Unit 4 queue
Dabbal Singh Mahara
 

Similar to Stacks in data structure (20)

PDF
The Stack (Data Structccccccccccccccccccc
parwarsmko98
 
PPTX
5.-Stacks.pptx
iloveyoucarlo0923
 
PPTX
DSA_Lecture4-Stack.pptx
TahaIrfan14
 
PPTX
Stacks in Data Structure
Lovely Professional University
 
PPTX
STACK.pptx
Dr.Shweta
 
PDF
4-Stack --------------------------------in C++.pdf
ab6399671
 
PPTX
My lecture stack_queue_operation
Senthil Kumar
 
PPTX
Stack PPT.pptx
UzmaRizvi5
 
PDF
STACK ( LIFO STRUCTURE) - Data Structure
Yaksh Jethva
 
PPTX
Data structure
krishna partiwala
 
PDF
LEC3-DS ALGO(updated).pdf
MuhammadUmerIhtisham
 
PDF
Chapter 5 Stack and Queue.pdf
GirT2
 
PPTX
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 
PDF
Stack push pop
A. S. M. Shafi
 
PDF
Stack
Amrutha Rajan
 
PPTX
CD3291 2.5 stack.pptx
mareeswari15
 
PPTX
Stacks in c++
Vineeta Garg
 
PPT
week 7,8,10,11 alll files included from .ppt
LidetAdmassu
 
PPTX
Data structure Stack
Praveen Vishwakarma
 
The Stack (Data Structccccccccccccccccccc
parwarsmko98
 
5.-Stacks.pptx
iloveyoucarlo0923
 
DSA_Lecture4-Stack.pptx
TahaIrfan14
 
Stacks in Data Structure
Lovely Professional University
 
STACK.pptx
Dr.Shweta
 
4-Stack --------------------------------in C++.pdf
ab6399671
 
My lecture stack_queue_operation
Senthil Kumar
 
Stack PPT.pptx
UzmaRizvi5
 
STACK ( LIFO STRUCTURE) - Data Structure
Yaksh Jethva
 
Data structure
krishna partiwala
 
LEC3-DS ALGO(updated).pdf
MuhammadUmerIhtisham
 
Chapter 5 Stack and Queue.pdf
GirT2
 
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 
Stack push pop
A. S. M. Shafi
 
CD3291 2.5 stack.pptx
mareeswari15
 
Stacks in c++
Vineeta Garg
 
week 7,8,10,11 alll files included from .ppt
LidetAdmassu
 
Data structure Stack
Praveen Vishwakarma
 
Ad

Recently uploaded (20)

PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Ad

Stacks in data structure

  • 1. Stacks Stack is an abstract data type with a bounded(predefined) capacity. It is a simple data structure that allows adding and removing elements in a particular order. Every time an element is added, it goes on the top of the stack, the only element that can be removed is the element that was at the top of the stack, just like a pile of objects. Basic features of Stack 1. Stack is an ordered list of similar data type. 2. Stack is a LIFO structure. (Last in First out). 3. push() function is used to insert new elements into the Stack and pop() is used to delete an element from the stack. Both insertion and deletion are allowed at only one end of Stack called Top. 4. Stack is said to be in Overflow state when it is completely full and is said to be in Underflow state if it is completely empty. Applications of Stack The simplest application of a stack is to reverse a word. You push a given word to stack - letter by letter - and then pop letters from the stack. There are other uses also like : Parsing, Expression Conversion(Infixto Postfix, Postfix to Prefix etc) and many more.
  • 2. Implementation of Stack Stack can be easily implemented using an Array or a Linked List. Arrays are quick, but are limited in size and Linked List requires overhead to allocate, link, unlink, and deallocate, but is not limited in size. Here we will implement Stack using array. /* Below program is written in C++ language */ Class Stack { int top; public: int a[10]; //Maximum size of Stack Stack() { top = -1; } }; void Stack::push(int x) { if( top >= 10) {
  • 3. cout << "Stack Overflow"; } else { a[++top] = x; cout << "Element Inserted"; } } int Stack::pop() { if(top < 0) { cout << "Stack Underflow"; return 0; } else { int d = a[top--]; return d; } } void Stack::isEmpty() { if(top < 0) { cout << "Stack is empty"; } else { cout << "Stack is not empty"; } }
  • 4. Position of Top Status of Stack -1 Stack is Empty 0 Only one element in Stack N-1 Stack is Full N Overflow state of Stack Analysis of Stacks Below mentioned are the time complexities for various operations that can be performed on the Stack data structure.  Push Operation : O(1)  Pop Operation : O(1)  Top Operation : O(1)  Search Operation : O(n)