SlideShare a Scribd company logo
1 of 18
Queue
Queue
Definition:-A queue is another special kind of list, where items are
inserted at one end called the rear and deleted at the other end
called the front. Another name for a queue is a “FIFO” or “First-in-
first-out” list.
Example:-Queue of people who are waiting for city
Bus at bus stop.
Primary queue operations:
• Enqueue: insert an element at the rear of the queue
• Dequeue: remove an element from the front of the queue
Applications of Queue:
1. It is used to schedule the jobs to be processed by the CPU.
2. When multiple users send print jobs to a printer, each printing job
is kept in the printing queue. Then the printer prints those jobs
according to first in first out (FIFO) basis.
3. Breadth first search uses a queue data structure to find an element
from a graph.
Let us consider a queue, which can hold maximum of Six elements. Initially the queue
is empty.
Now it is not possible to insert an element 66 (rear cross the max size means queue
overflow)even though there are two vacant positions in the linear queue. To over come
this problem .we discuss circular Queue.
C implementation of Queue
Continue….
Circular Queue
Circular queue is implemented by making a array of queue
circular. This implementation of a queue is called a
circular queue because it uses its storage array as if it
were a circle instead of a linear list.
There are two problems associated with linear queue. They
are:
• Time consuming: linear time to be spent in shifting the
elements to the beginning of the queue.
• Signaling queue full: even if the queue is having vacant
position.
Let us consider a queue of size 6(queue[5]),initialy front =-1 & rear =-1
rear= (rear+1) % max_size
front= (front+1) % max_size
Insertion in circular queue implemented by:
Delition in circular queue implemented by:
C implementation of circular queue
# define max 5
int rear=-1;
int front=-1;
int queue[max];
void queue_insert()
{
int item;
if(front==(rear+1)%max)
{
printf("nYour queue is full");
}
else
{ printf("nEnter the item:");
scanf("%d",&item);
if(front==-1)
{ rear=0;front=0;
queue[rear]=item;
}
else
{
rear=(rear+1)%max;
queue[rear]=item;
void queue_delete()
{
int item;
if(front==-1)
{
printf("nYour queue is empty");
}
else
{
item=queue[front];
if(front==rear)
{
front=-1; rear=-1;
printf("nYour deleted item is:%d",item);
}
else
{
front=(front+1)%max;
printf("nYour deleted item is:%d",item);
}
}
}
void display()
{ int i;
if(front== -1)
{
printf("nYour queue is empty");
}
else
{
if(front>rear)
{
for(i=front;i<max;i++)
{
printf("nqueue is:%d",queue[i]);
}
for(i=0;i<=rear;i++)
{
printf("nqueue is:%d",queue[i]);
}
}
else
{
for(i=front;i<=rear;i++)
{ printf("nqueue is:%d",queue[i]);
}}} }
void main()
{ int choice;
char ch;
clrscr();
do
{
printf("nEnter the option:");
printf("n1.Insert");
printf("n2.Delete");
printf("n3.Display");
printf("nYour choice:");
scanf("%d",&choice);
switch(choice)
{
case 1: queue_insert();
break;
case 2: queue_delete();
break;
case 3: display();
break;
}
printf("nIf you want to continue press Y:");
scanf("%c",&ch);
}while(ch=='y');
getch();}
scanf
DEQUEUE (OR) DEQUE (DOUBLE ENDED QUEUE)
• DeQueue is a data structure in which elements may be added to or deleted from the
front or the rear.
• It support the following operation:-
insert from front
delete from front
insert from rear
delete from rear
int front=-1;
int rear=-1;
#define max 5
int dequeue[max];
#include<stdio.h>
#include<conio.h>
void insert_rear()
{
int item;
if(rear==max-1)
printf("nYour Queue is Full");
else
{
printf("nEnter the item:");
scanf("%d",&item);
if(rear==-1)
{
front=0; rear=0;
dequeue[rear]=item;
}
else
{
rear=rear+1;
dequeue[rear]=item;
} } }
void delete_rear()
{
int item;
if(front==-1)
printf("nYour Dequeue is empty");
else
{
if(rear==front)
{
item=dequeue[rear];
rear=-1;front=-1;
printf("nYour deleted item is:%d",item);
}
else
{
item=dequeue[rear];
rear=rear-1;
printf("nYour deleted item is:%d",item);
}
}
}
void insert_front()
{
int item;
if(front==0)
printf("nYour queue is full");
else
{
printf("nEnter your item:");
scanf("%d",&item);
front=front-1;
dequeue[front]=item;
}
}
void display()
{ int i;
for(i=front;i<=rear;i++)
{
printf("nYour queue is %d",dequeue[i]);
}
}
void delete_front()
{
int item;
if(front==-1)
printf("nYour dequeue is empty");
else
{
if(front==rear)
{
item=dequeue[front];
front=-1;rear=-1;
printf("nYour delelted item is:%d",item);
}
else
{
item=dequeue[front];
front=front+1;
printf("nYour deleted item is:%d",item);
}
}
}
void main()
{
int choice;
char ch;
do
{
printf("nChoose the option:");
printf("n1.Insert Rear");
printf("n2.Delete Rear");
printf("n3.Insert Front");
printf("n4.Delete Front");
printf("n5.Display");
printf("n Enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1: insert_rear();
break;
case 2: delete_rear();
break;
case 3: insert_front();
break;
case 4: delete_front();
break;
case 5: display();
break;
}
printf("nIf you want to continue press y:");
scanf("%s",&ch);
}while(ch=='y');
getch();
}
Priority Queue:
A priority queue is a collection of elements such that each element has been assigned
a priority and such that the order in which elements are deleted and processed
comes from the following rules:
1. An element of higher priority is processed before any element of lower
priority.
2. two elements with same priority are processed according to the order in
which they were added to the queue.
A prototype of a priority queue is time sharing system: programs of high priority are
processed first, and programs with the same priority form a standard queue. An
efficient implementation for the Priority Queue is to use heap, which in turn can be
used for sorting purpose called heap sort.

More Related Content

Similar to Queue(lecture8).pptx

Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddumaneesh boddu
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptxNuraMohamed9
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبياناتRafal Edward
 
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 QueueBalwant Gorad
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
CEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdfCEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdfvtunali
 
Queues presentation
Queues presentationQueues presentation
Queues presentationToseef Hasan
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Self-Employed
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 

Similar to Queue(lecture8).pptx (20)

Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
DS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptxDS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptx
 
Queue
QueueQueue
Queue
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
stack & queue
stack & queuestack & queue
stack & queue
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
 
Queue
QueueQueue
Queue
 
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
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
CEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdfCEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdf
 
Queue
QueueQueue
Queue
 
data structure
data structuredata structure
data structure
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
 

Recently uploaded

How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxakanksha16arora
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 

Recently uploaded (20)

How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 

Queue(lecture8).pptx

  • 2. Queue Definition:-A queue is another special kind of list, where items are inserted at one end called the rear and deleted at the other end called the front. Another name for a queue is a “FIFO” or “First-in- first-out” list. Example:-Queue of people who are waiting for city Bus at bus stop. Primary queue operations: • Enqueue: insert an element at the rear of the queue • Dequeue: remove an element from the front of the queue Applications of Queue: 1. It is used to schedule the jobs to be processed by the CPU. 2. When multiple users send print jobs to a printer, each printing job is kept in the printing queue. Then the printer prints those jobs according to first in first out (FIFO) basis. 3. Breadth first search uses a queue data structure to find an element from a graph.
  • 3. Let us consider a queue, which can hold maximum of Six elements. Initially the queue is empty. Now it is not possible to insert an element 66 (rear cross the max size means queue overflow)even though there are two vacant positions in the linear queue. To over come this problem .we discuss circular Queue.
  • 6. Circular Queue Circular queue is implemented by making a array of queue circular. This implementation of a queue is called a circular queue because it uses its storage array as if it were a circle instead of a linear list. There are two problems associated with linear queue. They are: • Time consuming: linear time to be spent in shifting the elements to the beginning of the queue. • Signaling queue full: even if the queue is having vacant position.
  • 7. Let us consider a queue of size 6(queue[5]),initialy front =-1 & rear =-1
  • 8.
  • 9. rear= (rear+1) % max_size front= (front+1) % max_size Insertion in circular queue implemented by: Delition in circular queue implemented by:
  • 10.
  • 11.
  • 12. C implementation of circular queue # define max 5 int rear=-1; int front=-1; int queue[max]; void queue_insert() { int item; if(front==(rear+1)%max) { printf("nYour queue is full"); } else { printf("nEnter the item:"); scanf("%d",&item); if(front==-1) { rear=0;front=0; queue[rear]=item; } else { rear=(rear+1)%max; queue[rear]=item; void queue_delete() { int item; if(front==-1) { printf("nYour queue is empty"); } else { item=queue[front]; if(front==rear) { front=-1; rear=-1; printf("nYour deleted item is:%d",item); } else { front=(front+1)%max; printf("nYour deleted item is:%d",item); } } }
  • 13. void display() { int i; if(front== -1) { printf("nYour queue is empty"); } else { if(front>rear) { for(i=front;i<max;i++) { printf("nqueue is:%d",queue[i]); } for(i=0;i<=rear;i++) { printf("nqueue is:%d",queue[i]); } } else { for(i=front;i<=rear;i++) { printf("nqueue is:%d",queue[i]); }}} } void main() { int choice; char ch; clrscr(); do { printf("nEnter the option:"); printf("n1.Insert"); printf("n2.Delete"); printf("n3.Display"); printf("nYour choice:"); scanf("%d",&choice); switch(choice) { case 1: queue_insert(); break; case 2: queue_delete(); break; case 3: display(); break; } printf("nIf you want to continue press Y:"); scanf("%c",&ch); }while(ch=='y'); getch();} scanf
  • 14. DEQUEUE (OR) DEQUE (DOUBLE ENDED QUEUE) • DeQueue is a data structure in which elements may be added to or deleted from the front or the rear. • It support the following operation:- insert from front delete from front insert from rear delete from rear
  • 15. int front=-1; int rear=-1; #define max 5 int dequeue[max]; #include<stdio.h> #include<conio.h> void insert_rear() { int item; if(rear==max-1) printf("nYour Queue is Full"); else { printf("nEnter the item:"); scanf("%d",&item); if(rear==-1) { front=0; rear=0; dequeue[rear]=item; } else { rear=rear+1; dequeue[rear]=item; } } } void delete_rear() { int item; if(front==-1) printf("nYour Dequeue is empty"); else { if(rear==front) { item=dequeue[rear]; rear=-1;front=-1; printf("nYour deleted item is:%d",item); } else { item=dequeue[rear]; rear=rear-1; printf("nYour deleted item is:%d",item); } } }
  • 16. void insert_front() { int item; if(front==0) printf("nYour queue is full"); else { printf("nEnter your item:"); scanf("%d",&item); front=front-1; dequeue[front]=item; } } void display() { int i; for(i=front;i<=rear;i++) { printf("nYour queue is %d",dequeue[i]); } } void delete_front() { int item; if(front==-1) printf("nYour dequeue is empty"); else { if(front==rear) { item=dequeue[front]; front=-1;rear=-1; printf("nYour delelted item is:%d",item); } else { item=dequeue[front]; front=front+1; printf("nYour deleted item is:%d",item); } } }
  • 17. void main() { int choice; char ch; do { printf("nChoose the option:"); printf("n1.Insert Rear"); printf("n2.Delete Rear"); printf("n3.Insert Front"); printf("n4.Delete Front"); printf("n5.Display"); printf("n Enter your choice:"); scanf("%d",&choice); switch(choice) { case 1: insert_rear(); break; case 2: delete_rear(); break; case 3: insert_front(); break; case 4: delete_front(); break; case 5: display(); break; } printf("nIf you want to continue press y:"); scanf("%s",&ch); }while(ch=='y'); getch(); }
  • 18. Priority Queue: A priority queue is a collection of elements such that each element has been assigned a priority and such that the order in which elements are deleted and processed comes from the following rules: 1. An element of higher priority is processed before any element of lower priority. 2. two elements with same priority are processed according to the order in which they were added to the queue. A prototype of a priority queue is time sharing system: programs of high priority are processed first, and programs with the same priority form a standard queue. An efficient implementation for the Priority Queue is to use heap, which in turn can be used for sorting purpose called heap sort.