SlideShare une entreprise Scribd logo
1  sur  17
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 (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

An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...nhezmainit1
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxRugvedSathawane
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 

Dernier (20)

An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
PS-Policies-on-Enrolment-Transfer-of-Docs-Checking-of-School-Forms-and-SF10-a...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 

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