SlideShare a Scribd company logo
1 of 21
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

Similar to Stack & Queue (20)

Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Queue and its operations
Queue and its operationsQueue and its operations
Queue and its operations
 
Lecture5
Lecture5Lecture5
Lecture5
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Queue
QueueQueue
Queue
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Stack project
Stack projectStack project
Stack project
 
Queue data structures and operation on data structures
Queue data structures and operation on data structuresQueue data structures and operation on data structures
Queue data structures and operation on data structures
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structure
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 

More from Hasan Mahadi Riaz

“Transparent Solar Cells: Future of Electricity”
“Transparent Solar Cells: Future of Electricity”“Transparent Solar Cells: Future of Electricity”
“Transparent Solar Cells: Future of Electricity”Hasan Mahadi Riaz
 
The Importance of public speaking
The Importance of public speakingThe Importance of public speaking
The Importance of public speakingHasan Mahadi Riaz
 
Computer Engineering on Business Sectors in the Context of Bangladesh.
Computer Engineering on Business Sectors in the Context of Bangladesh.Computer Engineering on Business Sectors in the Context of Bangladesh.
Computer Engineering on Business Sectors in the Context of Bangladesh.Hasan Mahadi Riaz
 
reduction and oxidation reactions.pptx
reduction and oxidation reactions.pptxreduction and oxidation reactions.pptx
reduction and oxidation reactions.pptxHasan Mahadi Riaz
 
Vocal qualities needed for fruitful verbal communication
Vocal qualities needed for fruitful verbal communicationVocal qualities needed for fruitful verbal communication
Vocal qualities needed for fruitful verbal communicationHasan Mahadi Riaz
 

More from Hasan Mahadi Riaz (7)

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

Recently uploaded

(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

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(); }