SlideShare a Scribd company logo
`
Stack
Sudipta Samanta
27500123050
Data Structure & Algorithm
PCC-CS301
2024-2025
What is a stack ?
 Stack is a linear data structure in which an element is inserted or deleted only
from the Top position.
Stack is based on last in first out (LIFO) property . it means the element inserted
first will be the last one to delete.
Basic operations of stack :
1. Push()
2. Pop()
3. Peek()
4. isFull()
5. isEmpty()
Implement of Push
operation:
void push()
{
If(top==maxsize-1)
{
printf(“Stack is full”);
return 0;
}
int num;
printf(“enter the element to be pushed”)
}
Scanf(“%d”,& num);
Top=top+1;
Stack[top]=num;
}
Push operation
The process of putting a new data element onto stack is known as push operation.
Algorithm for push operation:
Step 1- Check if the stack is full.
Step 2- If the stack is full, produces
an error and exit.
Step 3- If the stack is not full,
increments top to point next empty
space.
Step 4- Adds data element to the
stack location, where top is
pointing.
Step 5- Returns success.
Implement of Pop
operation:
void pop()
{
If(top== -1)
{
printf(“Stack is empty”);
return -1;
}
int num;
num=stack[top];
printf(“Element poped from stack: %d”,num);
top=top-1;
}
Pop operation
The process of deleting an element from the top of the stack is called pop operation.
After every pop operation, the top of stack is decremented by 1.
Algorithm for pop operation:
Step 1- Check if the stack is empty.
Step 2- If the stack is empty,
produces an error and exit.
Step 3- If the stack is not empty,
accesses the data element at which
top is pointing.
Step 4- Decreases the value of top
by 1.
Step 5- Returns success.
 Peek Operation: Returns the value of the top element without
removing it from the stack.
int peek()
{
return stack[top];
}
 isFull() Operation: Returns true if the stack is full.
bool isFull()
{
if(top==Maxsize)
return true;
else{
return false;
}
 isEmpty() Operation: Returns true if the stack is empty
and false if it’s not.
bool isEmpty()
{
if(top==-1)
return true;
else{
return false;
}
Stack Errors
Stack Overflow:
when stack is completely full (i.e Top=maxsize-1) and we try to insert
more elements onto stack then this condition is called overflow condition.
Stack underflow:
when stack is empty(i.e Top= -1) and we try to delete more element from
it then this condition is called underflow condition.
Thank You !

More Related Content

PPTX
The presentation on stack data structure
PDF
Algorithm and Data Structure - Stack
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
PPTX
Stack,queue and linked list data structure.pptx
PDF
PPTX
STACKS implimentarions AND stack applications .pptx
PDF
Stacks-and-Queues.pdf
PPTX
Data Structures Stack and Queue Data Structures
The presentation on stack data structure
Algorithm and Data Structure - Stack
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Stack,queue and linked list data structure.pptx
STACKS implimentarions AND stack applications .pptx
Stacks-and-Queues.pdf
Data Structures Stack and Queue Data Structures

Similar to stack_ppt_DSA(sudipta samanta).pptx push,pop,peek operation (20)

PPTX
STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx
PPTX
Stack and its operation implemented with array new - Copy.pptx
PDF
Data structure week y 5
DOCX
Stack - Operations and Applications
PPTX
Stack and its operations, Queue and its operations
DOCX
DSA- Unit III- STACK AND QUEUE
PPT
The Stack in data structures .ppt
DOCX
In C++ a function used to put data into a stack is typically called a.docx
PPTX
Stack.pptx
PDF
PPTX
PPT
Stack in Data Structure
PPTX
Stack Data Structure
PPTX
Stack and queue
PPTX
Stack organization
PPTX
Stack and Queue.pptx university exam preparation
PPT
Stacks
PPT
Stack data structures with definition and code
PPTX
6 - STACKS in Data Structure and Algorithm.pptx
PPTX
Chapter 5-stack.pptx
STACK_IN_DATA STRUCTURE AND ALGORITHMS.pptx
Stack and its operation implemented with array new - Copy.pptx
Data structure week y 5
Stack - Operations and Applications
Stack and its operations, Queue and its operations
DSA- Unit III- STACK AND QUEUE
The Stack in data structures .ppt
In C++ a function used to put data into a stack is typically called a.docx
Stack.pptx
Stack in Data Structure
Stack Data Structure
Stack and queue
Stack organization
Stack and Queue.pptx university exam preparation
Stacks
Stack data structures with definition and code
6 - STACKS in Data Structure and Algorithm.pptx
Chapter 5-stack.pptx
Ad

Recently uploaded (20)

PDF
composite construction of structures.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Well-logging-methods_new................
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Geodesy 1.pptx...............................................
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
composite construction of structures.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Well-logging-methods_new................
UNIT-1 - COAL BASED THERMAL POWER PLANTS
CH1 Production IntroductoryConcepts.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Mechanical Engineering MATERIALS Selection
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Geodesy 1.pptx...............................................
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Model Code of Practice - Construction Work - 21102022 .pdf
Foundation to blockchain - A guide to Blockchain Tech
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
bas. eng. economics group 4 presentation 1.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Sustainable Sites - Green Building Construction
Internet of Things (IOT) - A guide to understanding
CYBER-CRIMES AND SECURITY A guide to understanding
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Ad

stack_ppt_DSA(sudipta samanta).pptx push,pop,peek operation

  • 1. ` Stack Sudipta Samanta 27500123050 Data Structure & Algorithm PCC-CS301 2024-2025
  • 2. What is a stack ?  Stack is a linear data structure in which an element is inserted or deleted only from the Top position. Stack is based on last in first out (LIFO) property . it means the element inserted first will be the last one to delete. Basic operations of stack : 1. Push() 2. Pop() 3. Peek() 4. isFull() 5. isEmpty()
  • 3. Implement of Push operation: void push() { If(top==maxsize-1) { printf(“Stack is full”); return 0; } int num; printf(“enter the element to be pushed”) } Scanf(“%d”,& num); Top=top+1; Stack[top]=num; } Push operation The process of putting a new data element onto stack is known as push operation. Algorithm for push operation: Step 1- Check if the stack is full. Step 2- If the stack is full, produces an error and exit. Step 3- If the stack is not full, increments top to point next empty space. Step 4- Adds data element to the stack location, where top is pointing. Step 5- Returns success.
  • 4. Implement of Pop operation: void pop() { If(top== -1) { printf(“Stack is empty”); return -1; } int num; num=stack[top]; printf(“Element poped from stack: %d”,num); top=top-1; } Pop operation The process of deleting an element from the top of the stack is called pop operation. After every pop operation, the top of stack is decremented by 1. Algorithm for pop operation: Step 1- Check if the stack is empty. Step 2- If the stack is empty, produces an error and exit. Step 3- If the stack is not empty, accesses the data element at which top is pointing. Step 4- Decreases the value of top by 1. Step 5- Returns success.
  • 5.  Peek Operation: Returns the value of the top element without removing it from the stack. int peek() { return stack[top]; }  isFull() Operation: Returns true if the stack is full. bool isFull() { if(top==Maxsize) return true; else{ return false; }  isEmpty() Operation: Returns true if the stack is empty and false if it’s not. bool isEmpty() { if(top==-1) return true; else{ return false; }
  • 6. Stack Errors Stack Overflow: when stack is completely full (i.e Top=maxsize-1) and we try to insert more elements onto stack then this condition is called overflow condition. Stack underflow: when stack is empty(i.e Top= -1) and we try to delete more element from it then this condition is called underflow condition.