SlideShare une entreprise Scribd logo
z
Presentation Topic
Dynamic Queue.
z
Queues
 A Queue is a special kind of list, where
items are inserted at one end (the rear)
And deleted at the other end (the front).
 Accessing the elements of queues follows
a First In First Out (FIFO) order.
 Example
 Like customers standing in a check-out
line in a store, the first customer in is
the first customer served.
2
z
Common Operations on Queues
 getFRONT(Q): Returns the first element on
Queue Q.
 ENQUEUE(x,Q): Inserts element x at the
end of Queue Q.
 DEQUEUE(Q): Deletes the first element of
Q.
 ISEMPTY(Q): Returns true if and only if Q
is an empty queue.
 ISFULL(Q): Returns true if and only if Q is
full.
3
z
Enqueue and Dequeue
 Primary queue operations: Enqueue and
Dequeue
 Enqueue – insert an element at the rear of
the queue.
 Dequeue – remove an element from the
front of the queue.
4
z
Queues Implementations
Static:
Queue is implemented by an array, and size
of queue remains fix
Dynamic:
A queue can be implemented as a linked
list and expand or shrink with each enqueue
or dequeue operation.
5
z
Static Implementation of Queues
6
z
Dynamic Implementation of Queues
Dynamic implementation is done using pointers.
• Front : A pointer to the first element of the
queue.
• Rear : A pointer to the last element of the
queue.
7
x y z
Front
Rear
.
z
Dynamic Implemenatation
• Enqueue (X)
• Enqueue (Y)
8
Q.front
Q.Rear
.
x
Q.front
Q.Rear
x .
y
z
Dynamic Implementation
• Dequeue:
• MakeNULL:
9
Q.front
Q.Rear
.
y
Q.front
Q.Rear
NULL
z
Dynamic implementation of Queue
struct queueNode
{
int num;
queueNode next;
};
queueNode front = NULL;
queueNode rear = NULL;
class dynQueue{
int size;
10
public:
dynQueue();
void enqueue();
void dequeue();
bool isEmpty();
void displayQueue();
void makeNull();
};
z
Constructor
dynQueue()
{
size=0;
}
11
z Enqueue( ) Function
Void enqueue(int x)
{
/*Linked list node*/
queueNode *n = new Node();
n->setData(x);
n->Next= NULL;
12
if (front == NULL)
{
front = n;
rear = n;
size++;
}
else
{
rear->Next=n;
rear = n;
size++;
}
}
z
Dequeue( ) Function
int dequeue()
{
if(front == NULL)
{
cout<<“Queue is Empty“;
}
else
{ queueNode *temp=front;
int x = front->getData();
front = front->getNext();
Delete temp;
return x;
}
}
13
z
getFront() and isEmpty()
int getFront()
{
return front->Data;
}
int isEmpty()
{
return ( front == NULL );
}
14
z
Display( ) Function
void display()
{
if(isEmpty())
cout<<“Queue is empty“;
else
{
for (int i=0; i<counter; i++)
cout<<queue[(front+ i)% maxSize];
}
}
15
z
Use of Queues
Out of the numerous uses of the queues, one of the most
useful is simulation.
A simulation program attempts to model a real-world
phenomenon.
Many popular video games are simulations, e.g., SimCity,
Flight Simulator.
Each object and action in the simulation has a counterpart in
real world.
16
z
Uses of Queues
If the simulation is accurate, the result of the program should
mirror the results of the real-world event.
Thus it is possible to understand what occurs in the real-world
without actually observing its occurrence.
17

Contenu connexe

Similaire à Dynamic Queue.pptx

queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
RAtna29
 
computer notes - Memory organization
computer notes - Memory organizationcomputer notes - Memory organization
computer notes - Memory organization
ecomputernotes
 

Similaire à Dynamic Queue.pptx (20)

Data structure.ppt
Data structure.pptData structure.ppt
Data structure.ppt
 
Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue
QueueQueue
Queue
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Queue
QueueQueue
Queue
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
(chapter 9) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 9) A Concise and Practical Introduction to Programming Algorithms in...(chapter 9) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 9) A Concise and Practical Introduction to Programming Algorithms in...
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Queues-handouts
Queues-handoutsQueues-handouts
Queues-handouts
 
QUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING CQUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING C
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
computer notes - Memory organization
computer notes - Memory organizationcomputer notes - Memory organization
computer notes - Memory organization
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
02 stackqueue
02 stackqueue02 stackqueue
02 stackqueue
 
Unit 5 dsa QUEUE
Unit 5 dsa QUEUEUnit 5 dsa QUEUE
Unit 5 dsa QUEUE
 

Dernier

Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
YibeltalNibretu
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 

Dernier (20)

Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

Dynamic Queue.pptx

  • 2. z Queues  A Queue is a special kind of list, where items are inserted at one end (the rear) And deleted at the other end (the front).  Accessing the elements of queues follows a First In First Out (FIFO) order.  Example  Like customers standing in a check-out line in a store, the first customer in is the first customer served. 2
  • 3. z Common Operations on Queues  getFRONT(Q): Returns the first element on Queue Q.  ENQUEUE(x,Q): Inserts element x at the end of Queue Q.  DEQUEUE(Q): Deletes the first element of Q.  ISEMPTY(Q): Returns true if and only if Q is an empty queue.  ISFULL(Q): Returns true if and only if Q is full. 3
  • 4. z Enqueue and Dequeue  Primary queue operations: Enqueue and Dequeue  Enqueue – insert an element at the rear of the queue.  Dequeue – remove an element from the front of the queue. 4
  • 5. z Queues Implementations Static: Queue is implemented by an array, and size of queue remains fix Dynamic: A queue can be implemented as a linked list and expand or shrink with each enqueue or dequeue operation. 5
  • 7. z Dynamic Implementation of Queues Dynamic implementation is done using pointers. • Front : A pointer to the first element of the queue. • Rear : A pointer to the last element of the queue. 7 x y z Front Rear .
  • 8. z Dynamic Implemenatation • Enqueue (X) • Enqueue (Y) 8 Q.front Q.Rear . x Q.front Q.Rear x . y
  • 9. z Dynamic Implementation • Dequeue: • MakeNULL: 9 Q.front Q.Rear . y Q.front Q.Rear NULL
  • 10. z Dynamic implementation of Queue struct queueNode { int num; queueNode next; }; queueNode front = NULL; queueNode rear = NULL; class dynQueue{ int size; 10 public: dynQueue(); void enqueue(); void dequeue(); bool isEmpty(); void displayQueue(); void makeNull(); };
  • 12. z Enqueue( ) Function Void enqueue(int x) { /*Linked list node*/ queueNode *n = new Node(); n->setData(x); n->Next= NULL; 12 if (front == NULL) { front = n; rear = n; size++; } else { rear->Next=n; rear = n; size++; } }
  • 13. z Dequeue( ) Function int dequeue() { if(front == NULL) { cout<<“Queue is Empty“; } else { queueNode *temp=front; int x = front->getData(); front = front->getNext(); Delete temp; return x; } } 13
  • 14. z getFront() and isEmpty() int getFront() { return front->Data; } int isEmpty() { return ( front == NULL ); } 14
  • 15. z Display( ) Function void display() { if(isEmpty()) cout<<“Queue is empty“; else { for (int i=0; i<counter; i++) cout<<queue[(front+ i)% maxSize]; } } 15
  • 16. z Use of Queues Out of the numerous uses of the queues, one of the most useful is simulation. A simulation program attempts to model a real-world phenomenon. Many popular video games are simulations, e.g., SimCity, Flight Simulator. Each object and action in the simulation has a counterpart in real world. 16
  • 17. z Uses of Queues If the simulation is accurate, the result of the program should mirror the results of the real-world event. Thus it is possible to understand what occurs in the real-world without actually observing its occurrence. 17