SlideShare a Scribd company logo
Welcome To Our
Presentation On
Stack and Queue
Supervised By
Mujibur Rahman Majumdar
Lecturer
Dept. of Computer Science and Engineering
International Standard University
Group Name: "Dynamic Squad"
Group Member:
Md. Riazul Islam
ID: 201030015
Md. Zahidul Islam
ID: 201030032
Israt Jahan Mysha
ID: 201030009
Saurav Roy
ID: 201030012
Munya Dilshad
ID: 201030049
Muhammad Akib Jabed
ID: 201030035
Data Structure
Linear Data Structure
Non Linear Data Structure
ARRAY
QUEUE
STACK
What is Linear Data Structure?
In linear data structure, data is arranged in linear sequence.
Data items can be traversed in a single run.
In linear data structure elements are accessed or placed in
contiguous(together in sequence) memory location.
What is Stack?
A stack is called a last-in-first-out
(LIFO) collection. This means that the
last thing we added (pushed) is the first
thing that gets pulled (popped) off.
A stack is a sequence of items that are
accessible at only one end of the
sequence.
Operations that can be
performed on STACK
• PUSH: It is used to insert items into the
stack.
• POP: It is used to delete items from
stack.
• TOP: It represents the current location
of data in stack.
ALGORITHM OF INSERTION
IN STACK: (PUSH)
1. Insertion (a,top, item, max)
2. If top = max then
print 'Stack Overflow'
exit
else
3. top = top + 1
end if
4. a [top]= item
5. Exit
ALGORITHM OF DELETION
IN STACK: (POP) 1. Deletion(a,top,item)
2. If top=0 then
print ‘STACK
UNDERFLOW’
exit else
3. item=a[top] end if
4. top=top-1
5. Exit
ALGORITHM
OF DISPLAY
IN STACK:
1.Display(top,i,a[i])
2.If top=0 then
Print ‘STACK EMPTY’
Exit
Else
3. For i=top to 0
Print a[i]
End for
4.exit
E
S
R
E
V
E
R
TOP
STACK
APPLICATIONS OF
STACKS ARE:
Reversing Strings:
• A simple application of stack is
reversing strings.
To reverse a string , the characters of
string are pushed onto the stack one
by one as the string is read from left
to right.
• Once all the characters
of string are pushed onto stack, they
are popped one by one. Since the
character last pushed in comes out first,
subsequent pop operation results in the
reversal of the string.
For example:
To reverse the string ‘REVERSE’
the string isread from left to right
and its characters arepushed .
Like:
TOP
STACK
String Is:
REVERSE
E
S
R
E
V
E
R
What is Queue?
Queue is an ADT data structure similar to stack, except
that the first item to be inserted is the first one to be
removed.
This mechanism is called First-In-First-Out (FIFO).
Placing an item in a queue is called “insertion or enqueue”,
which is done at the end of the queue called “rear”.
Removing an item from a queue is called “deletion or
dequeue”, which is done at the other end of the queue
called “front”.
Some of the applications are : printer queue, keystroke
queue, etc.
Dqueue
It is a double-
ended queue.
Items can be
inserted and
deleted from either
ends.More
versatile data
structure than
stack or queue.
E.g. policy-based
application (e.g.
low priority go to
the end, high go to
the front)
In a case where
you want to sort
the queue once in
a while, What
sorting algorithm
will you use?
The operation of Queue:
1. Placing an item in a queue is called “insertion
or enqueue”, which is done at the end of
the queue called “rear”. Placing an item in a
queue is called “insertion or enqueue”, which is
done at the end of the queue called “rear”.
2. Removing an item from
a queue is called “deletion or dequeue”, which
is done at the other end of the queue
called “front".
Algorithm of Queue
1. If (rear = maxsize – 1)
print ("queue overflow") and return
2. Else
rear = rear + 1
queue [rear] = item
1. If (front = rear)
print ("queue empty") and return
2. Else
Front = Front + 1
item = queue [Front];
Return item
Q-INSERT Q-DELETE
Application of Queue
Real life examples
Waiting in line
Waiting on hold for
tech support
Applications
related to
Computer Science
Round robin
scheduling
Job scheduling
(FIFO Scheduling)
Key board buffer
Difference
between Stack
and Queue:
Stacks Queues
Stacks are based on the LIFO principle, i.e.,
the element inserted at the last, is the first
element to come out of the list.
Queues are based on the FIFO principle, i.e.,
the element inserted at the first, is the first
element to come out of the list.
Insertion and deletion in stacks takes place
only from one end of the list called the top.
Insertion and deletion in queues takes place
from the opposite ends of the list. The
insertion takes place at the rear of the list and
the deletion takes place from the front of the
list.
Insert operation is called push operation. Insert operation is called enqueue operation.
Delete operation is called pop operation. Delete operation is called dequeue operation.
In stacks we maintain only one pointer to
access the list, called the top, which always
points to the last element present in the list.
In queues we maintain two pointers to access
the list. The front pointer always points to the
first element inserted in the list and is still
present, and the rear pointer always points to
the last inserted element.
Stack is used in solving problems works on
recursion.
Queue is used in solving problems having
sequential processing.
Stack Push
Pop operation
#include <stdio.h>
int stack[8];
int top = -1,n;
int push(int data) {
if(top == n)
{
printf("nStack overflow");
}
else
{
top = top + 1;
stack[top] = data;
}
}
void pop()
{
if(top == -1)
printf("Underflow");
else
top = top -1;
}
void show()
{
printf("n");
for (int i=top;i>=0;i--)
{
printf("%dn",stack[i]);
}
if(top == -1)
{
printf("Stack is empty");
}
}
int main() {
Printf ("Maximum index in stack:
");
Scanf ("%d",&n);
push(3);
push(5);
push(9);
push(1);
push(12);
push(15);
show();
printf("n PoP operation");
pop();
show();
return 0;
}
Queue
Enqueue() and
dequeue()
operation
#include<stdio.h>
int queue[100],n;
int front = -1;
int rear = -1;
void enqueue(int num)
{
if(rear==n)
{
printf("nQueue overflow");
}
else
{
if(front==-1)
{
front =0;
}
rear = rear+1;
queue[rear] = num;
showQueue();
}
}
void dequeue()
{
if(front ==-1 || front>rear)
{
printf("nQueue underflow");
}
else
{
front = front +1;
showQueue();
}
}
void showQueue()
{
printf("n");
if(front==-1)
{
printf("Queue is empty");
}
else
{
for(int i = front;i<=rear;i++)
{
printf("%d ", queue[i]);
}
printf(" Front = %d and Rear =
%d",front,rear);
}
}
int main()
{
printf("Maximum index of queue: ");
scanf("%d",&n);
dequeue();
enqueue(5);
enqueue(7);
enqueue(1);
enqueue(1);
enqueue(1);
dequeue();
dequeue();
dequeue();
dequeue();
}
Any Query
Thank You!!

More Related Content

Similar to Stack & Queue (20)

PPSX
Data structure stack&queue basics
Selvin Josy Bai Somu
 
PPTX
data structure
Arvind Kumar
 
PPTX
Stack and Queue.pptx university exam preparation
RAtna29
 
PPTX
Stacks.pptx in software engineering in simple understanding
MohammedAnas871930
 
PPT
Difference between stack and queue
Pulkitmodi1998
 
PPT
Stack and queue
Anil Kumar Prajapati
 
PDF
9f556226-babd-4276-b964-371c6a5a77b9.pdf
kumarharsh2119hk
 
DOCX
CDS artificial intelligence and Machine.docx
msurfudeen6681
 
PPTX
VCE Unit 03vv.pptx
skilljiolms
 
PPTX
Stack and Queue.pptx
Ddushb
 
PPTX
Queues
nidhisatija1
 
PPTX
Queue and its operations
V.V.Vanniaperumal College for Women
 
PPTX
Lecture 2 Introduction to Stacks and Queues.pptx
yhrcxd8wpm
 
PPTX
Data Structures - Lecture 2 - Unit 2.pptx
DanielNesaKumarC
 
PPTX
Ds stack & queue
Sunipa Bera
 
PPTX
stack & queue
manju rani
 
PDF
IRJET- Comparison of Stack and Queue Data Structures
IRJET Journal
 
PPTX
STACKS AND QUEUES.pptx
SKUP1
 
PPTX
STACKS AND QUEUES.pptx
LECO9
 
Data structure stack&queue basics
Selvin Josy Bai Somu
 
data structure
Arvind Kumar
 
Stack and Queue.pptx university exam preparation
RAtna29
 
Stacks.pptx in software engineering in simple understanding
MohammedAnas871930
 
Difference between stack and queue
Pulkitmodi1998
 
Stack and queue
Anil Kumar Prajapati
 
9f556226-babd-4276-b964-371c6a5a77b9.pdf
kumarharsh2119hk
 
CDS artificial intelligence and Machine.docx
msurfudeen6681
 
VCE Unit 03vv.pptx
skilljiolms
 
Stack and Queue.pptx
Ddushb
 
Queues
nidhisatija1
 
Queue and its operations
V.V.Vanniaperumal College for Women
 
Lecture 2 Introduction to Stacks and Queues.pptx
yhrcxd8wpm
 
Data Structures - Lecture 2 - Unit 2.pptx
DanielNesaKumarC
 
Ds stack & queue
Sunipa Bera
 
stack & queue
manju rani
 
IRJET- Comparison of Stack and Queue Data Structures
IRJET Journal
 
STACKS AND QUEUES.pptx
SKUP1
 
STACKS AND QUEUES.pptx
LECO9
 

More from Hasan Mahadi Riaz (7)

PPTX
“Transparent Solar Cells: Future of Electricity”
Hasan Mahadi Riaz
 
PPTX
The Importance of public speaking
Hasan Mahadi Riaz
 
PPTX
Computer Engineering on Business Sectors in the Context of Bangladesh.
Hasan Mahadi Riaz
 
PPTX
violence against women.pptx
Hasan Mahadi Riaz
 
PPTX
reduction and oxidation reactions.pptx
Hasan Mahadi Riaz
 
PPTX
Vocal qualities needed for fruitful verbal communication
Hasan Mahadi Riaz
 
PPTX
Distributed Arbitration
Hasan Mahadi Riaz
 
“Transparent Solar Cells: Future of Electricity”
Hasan Mahadi Riaz
 
The Importance of public speaking
Hasan Mahadi Riaz
 
Computer Engineering on Business Sectors in the Context of Bangladesh.
Hasan Mahadi Riaz
 
violence against women.pptx
Hasan Mahadi Riaz
 
reduction and oxidation reactions.pptx
Hasan Mahadi Riaz
 
Vocal qualities needed for fruitful verbal communication
Hasan Mahadi Riaz
 
Distributed Arbitration
Hasan Mahadi Riaz
 
Ad

Recently uploaded (20)

PDF
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
PPTX
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
PDF
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
PDF
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
PPT
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
PPTX
Bitumen Emulsion by Dr Sangita Ex CRRI Delhi
grilcodes
 
PDF
01-introduction to the ProcessDesign.pdf
StiveBrack
 
PPTX
CST413 KTU S7 CSE Machine Learning Introduction Parameter Estimation MLE MAP ...
resming1
 
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
 
PPTX
CST413 KTU S7 CSE Machine Learning Neural Networks and Support Vector Machine...
resming1
 
PPTX
Work at Height training for workers .pptx
cecos12
 
PDF
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
PDF
June 2025 Top 10 Sites -Electrical and Electronics Engineering: An Internatio...
elelijjournal653
 
PPTX
Computer network Computer network Computer network Computer network
Shrikant317689
 
PPTX
Precooling and Refrigerated storage.pptx
ThongamSunita
 
PPTX
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
 
PPTX
Mobile database systems 20254545645.pptx
herosh1968
 
PDF
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
 
PPTX
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
PPTX
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
Bitumen Emulsion by Dr Sangita Ex CRRI Delhi
grilcodes
 
01-introduction to the ProcessDesign.pdf
StiveBrack
 
CST413 KTU S7 CSE Machine Learning Introduction Parameter Estimation MLE MAP ...
resming1
 
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
 
CST413 KTU S7 CSE Machine Learning Neural Networks and Support Vector Machine...
resming1
 
Work at Height training for workers .pptx
cecos12
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
June 2025 Top 10 Sites -Electrical and Electronics Engineering: An Internatio...
elelijjournal653
 
Computer network Computer network Computer network Computer network
Shrikant317689
 
Precooling and Refrigerated storage.pptx
ThongamSunita
 
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
 
Mobile database systems 20254545645.pptx
herosh1968
 
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
 
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
Ad

Stack & Queue

  • 1. Welcome To Our Presentation On Stack and Queue
  • 2. Supervised By Mujibur Rahman Majumdar Lecturer Dept. of Computer Science and Engineering International Standard University
  • 3. Group Name: "Dynamic Squad" Group Member: Md. Riazul Islam ID: 201030015 Md. Zahidul Islam ID: 201030032 Israt Jahan Mysha ID: 201030009 Saurav Roy ID: 201030012 Munya Dilshad ID: 201030049 Muhammad Akib Jabed ID: 201030035
  • 4. Data Structure Linear Data Structure Non Linear Data Structure ARRAY QUEUE STACK
  • 5. What is Linear Data Structure? In linear data structure, data is arranged in linear sequence. Data items can be traversed in a single run. In linear data structure elements are accessed or placed in contiguous(together in sequence) memory location.
  • 6. What is Stack? A stack is called a last-in-first-out (LIFO) collection. This means that the last thing we added (pushed) is the first thing that gets pulled (popped) off. A stack is a sequence of items that are accessible at only one end of the sequence.
  • 7. Operations that can be performed on STACK • PUSH: It is used to insert items into the stack. • POP: It is used to delete items from stack. • TOP: It represents the current location of data in stack.
  • 8. ALGORITHM OF INSERTION IN STACK: (PUSH) 1. Insertion (a,top, item, max) 2. If top = max then print 'Stack Overflow' exit else 3. top = top + 1 end if 4. a [top]= item 5. Exit
  • 9. ALGORITHM OF DELETION IN STACK: (POP) 1. Deletion(a,top,item) 2. If top=0 then print ‘STACK UNDERFLOW’ exit else 3. item=a[top] end if 4. top=top-1 5. Exit
  • 10. ALGORITHM OF DISPLAY IN STACK: 1.Display(top,i,a[i]) 2.If top=0 then Print ‘STACK EMPTY’ Exit Else 3. For i=top to 0 Print a[i] End for 4.exit E S R E V E R TOP STACK
  • 11. APPLICATIONS OF STACKS ARE: Reversing Strings: • A simple application of stack is reversing strings. To reverse a string , the characters of string are pushed onto the stack one by one as the string is read from left to right. • Once all the characters of string are pushed onto stack, they are popped one by one. Since the character last pushed in comes out first, subsequent pop operation results in the reversal of the string. For example: To reverse the string ‘REVERSE’ the string isread from left to right and its characters arepushed . Like: TOP STACK String Is: REVERSE E S R E V E R
  • 12. What is Queue? Queue is an ADT data structure similar to stack, except that the first item to be inserted is the first one to be removed. This mechanism is called First-In-First-Out (FIFO). Placing an item in a queue is called “insertion or enqueue”, which is done at the end of the queue called “rear”. Removing an item from a queue is called “deletion or dequeue”, which is done at the other end of the queue called “front”. Some of the applications are : printer queue, keystroke queue, etc.
  • 13. Dqueue It is a double- ended queue. Items can be inserted and deleted from either ends.More versatile data structure than stack or queue. E.g. policy-based application (e.g. low priority go to the end, high go to the front) In a case where you want to sort the queue once in a while, What sorting algorithm will you use?
  • 14. The operation of Queue: 1. Placing an item in a queue is called “insertion or enqueue”, which is done at the end of the queue called “rear”. Placing an item in a queue is called “insertion or enqueue”, which is done at the end of the queue called “rear”. 2. Removing an item from a queue is called “deletion or dequeue”, which is done at the other end of the queue called “front".
  • 15. Algorithm of Queue 1. If (rear = maxsize – 1) print ("queue overflow") and return 2. Else rear = rear + 1 queue [rear] = item 1. If (front = rear) print ("queue empty") and return 2. Else Front = Front + 1 item = queue [Front]; Return item Q-INSERT Q-DELETE
  • 16. Application of Queue Real life examples Waiting in line Waiting on hold for tech support Applications related to Computer Science Round robin scheduling Job scheduling (FIFO Scheduling) Key board buffer
  • 17. Difference between Stack and Queue: Stacks Queues Stacks are based on the LIFO principle, i.e., the element inserted at the last, is the first element to come out of the list. Queues are based on the FIFO principle, i.e., the element inserted at the first, is the first element to come out of the list. Insertion and deletion in stacks takes place only from one end of the list called the top. Insertion and deletion in queues takes place from the opposite ends of the list. The insertion takes place at the rear of the list and the deletion takes place from the front of the list. Insert operation is called push operation. Insert operation is called enqueue operation. Delete operation is called pop operation. Delete operation is called dequeue operation. In stacks we maintain only one pointer to access the list, called the top, which always points to the last element present in the list. In queues we maintain two pointers to access the list. The front pointer always points to the first element inserted in the list and is still present, and the rear pointer always points to the last inserted element. Stack is used in solving problems works on recursion. Queue is used in solving problems having sequential processing.
  • 18. Stack Push Pop operation #include <stdio.h> int stack[8]; int top = -1,n; int push(int data) { if(top == n) { printf("nStack overflow"); } else { top = top + 1; stack[top] = data; } } void pop() { if(top == -1) printf("Underflow"); else top = top -1; } void show() { printf("n"); for (int i=top;i>=0;i--) { printf("%dn",stack[i]); } if(top == -1) { printf("Stack is empty"); } } int main() { Printf ("Maximum index in stack: "); Scanf ("%d",&n); push(3); push(5); push(9); push(1); push(12); push(15); show(); printf("n PoP operation"); pop(); show(); return 0; }
  • 19. Queue Enqueue() and dequeue() operation #include<stdio.h> int queue[100],n; int front = -1; int rear = -1; void enqueue(int num) { if(rear==n) { printf("nQueue overflow"); } else { if(front==-1) { front =0; } rear = rear+1; queue[rear] = num; showQueue(); } } void dequeue() { if(front ==-1 || front>rear) { printf("nQueue underflow"); } else { front = front +1; showQueue(); } } void showQueue() { printf("n"); if(front==-1) { printf("Queue is empty"); } else { for(int i = front;i<=rear;i++) { printf("%d ", queue[i]); } printf(" Front = %d and Rear = %d",front,rear); } } int main() { printf("Maximum index of queue: "); scanf("%d",&n); dequeue(); enqueue(5); enqueue(7); enqueue(1); enqueue(1); enqueue(1); dequeue(); dequeue(); dequeue(); dequeue(); }