SlideShare a Scribd company logo
Queues
SOUMEN SANTRA
MCA, M.Tech, SCJP, MCP
DEFINITION OF QUEUE
• A Queue is an ordered collection ADT(Abstract Data Type) of items
from which items may be deleted at one end (FRONT) and into
which items may be inserted at the other end (REAR).
• The first element inserted into the queue is the first element to be
removed. The queue is sometimes called a FIFO (first-in first-out) list
as opposed to the stack, which is a LIFO (last-in first-out).
Queue
• Stores a set of elements in a particular order
• Stack principle: FIRST IN FIRST OUT
• = FIFO
• It means: the first element inserted is the first one to be
removed.
• The first one in line is the first one to be served
• Example
Queue Applications
• Real life examples
• Waiting in line for reservation
• Waiting on hold for tech support
• Applications related to Computer Science
• Threads scheduling & synchronization
• Job scheduling (e.g. Round-Robin algorithm for CPU allocation)
A
B
A
C
B
A
D
C
B
A
D
C
Brear
front
rear
front
rear
front
rear
front
rear
front
First In First Out
front rear Q[0] Q[1] Q[2] Q[3] Comments
-1
-1
-1
-1
0
1
-1
0
1
2
2
2
J1
J1 J2
J1 J2 J3
J2 J3
J3
queue is empty
Job 1 is added
Job 2 is added
Job 3 is added
Job 1 is deleted
Job 2 is deleted
Applications: Job Scheduling
Queue
items[MAX-1]
. .
. .
. .
items[2] C
items[1] B
items[0] A Front=0
Rear=2
Declaration of a Queue
# define MAX 500 /* size of the queue items*/
typedef struct {
int front;
int rear;
int items[MAX];
}QUEUE;
QUEUE OPERATIONS
• Initialize the queue
• Insert to the rear of the queue
• Remove (Delete) from the front of the queue
• Is the Queue Empty
• Is the Queue Full
• What is the size of the Queue
Queue Example: Class Diagram Concept
+Queue()
+insert() : void
+remove() : long
+peekFront() : long
+isEmpty() : bool
+isFull() : bool
+size() : int
-maxSize : int
-queueArray [] : long
-front : int
-rear : int
-nItems : int
Queue
QueueApp
Interface1
INITIALIZE THE QUEUE
items[MAX-1]
. .
. .
.
items[1]
items[0] front=0
rear=-1
•The queue is initialized by having the rear set to -1, and front set to 0. Let us
assume that maximum number of the element we have in a queue is MAX size
elements as shown below.
insert(&Queue, ‘A’) Method
• an item (A) is inserted at the Rear of the queue
items[MAX-1]
. .
. .
items[3]
items[2]
items[1]
items[0] A Front=0,
Rear=0
insert(&Queue, ‘B’) Method
• A new item (B) is inserted at the Rear of the queue
items[MAX-1]
. .
. .
items[3]
items[2]
items[1] B Rear=1
items[0] A Front=0
insert(&Queue, ‘C’) Method
• A new item (C) is inserted at the Rear of the queue
items[MAX-1]
. .
. .
items[3]
items[2] C Rear=2
items[1] B
items[0] A Front=0
insert(&Queue, ‘D’) Method
• A new item (D) is inserted at the Rear of the queue
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B
items[0] A Front=0
Array-based Queue Implementation
• As with the array-based stack implementation, the array is
of fixed size
• A queue of maximum N elements
• Slightly more complicated
• Need to maintain CONTROL of both front and rear
Implementation 1
Implementation 2
Insert Operation of Queue using pointer
void insert(QUEUE *qptr, char x)
{
if(qptr->rear == MAX-1)
{
printf("Queue is full!");
exit(1);
}
else
{
qptr->rear++;
qptr->items[qptr->rear]=x;
}
}
char remove(&Queue) Method
• an item (A) is removed (deleted) from the Front of
the queue & return it as per datatype.
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B Front=1
items[0] A
char remove(&Queue) Method
• Remove two items from the front of the queue.
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C Front=2
items[1] B
items[0] A
char remove(&Queue) Method
• Remove two items from the front of the queue.
items[MAX-1]
. .
. .
items[3] D Front=Rear=3
items[2] C
items[1] B
items[0] A
char remove(&Queue) Method
• Remove one more item from the front of the queue.
items[MAX-1]
. .
items[4] Front=4
items[3] D Rear=3
items[2] C
items[1] B
items[0] A
Remove Operation implementation in c
char remove(struct queue *qptr)
{
char p;
if(qptr->front > qptr->rear){
printf("Queue is empty");
exit(1);
}
else
{p=qptr->items[qptr->front];
qptr->front++;
return p;
}
}
INSERT / REMOVE ITEMS : Drawback of Linear Queue
• Assume that the rear= MAX-1
•What happens if we want to insert a new
item into the queue?
items[MAX-1] X rear=MAX-1
. .
. .
items[3] D front=3
items[2] C
items[1] B
items[0] A
INSERT / REMOVE ITEMS
• What happens if we want to insert a new item F into the
queue?
• Although there is some empty space, the queue is full.
• One of the methods to overcome this problem is to shift all
the items to occupy the location of deleted item.
REMOVE ITEM
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B Front=1
items[0] A
REMOVE ITEM : Example
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B Front=1
items[0] B
REMOVE ITEM : Example
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] C
items[0] B
REMOVE ITEM : Example
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] D
items[1] C
items[0] B
REMOVE ITEM : Example
items[MAX-1]
. .
. .
items[3] D
items[2] D Rear=2
items[1] C
items[0] B
Modified Remove Operation implementation
in C
char remove(struct queue *qptr)
{
char p;
int i;
if(qptr->front > qptr->rear){
printf("Queue is empty");
exit(1);
}
else
{p=qptr->items[qptr->front];
for(i=1;i<=qptr->rear;i++)
qptr->items[i-1]=qptr->items[i];
qptr->rear--
return p;
}
}
INSERT / REMOVE ITEMS
• Since all the items in the queue are required to shift when an
item is deleted, this method is not preferred.
• The other method is circular queue.
• When rear = MAX-1, the next element is entered at items[0] in
case that spot is free.
How to Initialize the queue
items[6] front=rear=6
items[5]
items[4]
items[3]
items[2]
items[1]
items[0]
Insert operation in Circular Queue
items[6] front=6
items[5]
items[4]
items[3]
items[2]
items[1]
items[0] 1 rear=0
 Insert 1,2,3 to the rear of the queue.
Insert operation in Circular Queue
items[6] front=6
items[5]
items[4]
items[3]
items[2]
items[1] 2 rear=1
items[0] 1
 Insert 1,2,3 to the rear of the queue.
Insert operation in Circular Queue
• Insert 1,2,3 to the rear of the queue.
items[6] front=6
items[5]
items[4]
items[3]
items[2] 3 rear=2
items[1] 2
items[0] 1
Remove items from circular queue
• Remove two items from the queue.
items[6]
items[5]
items[4]
items[3]
items[2] 3 rear=2
items[1] 2
items[0] 1 front=0
Remove items from circular queue
• Remove two items from the queue.
items[6]
items[5]
items[4]
items[3]
items[2] 3 rear=2
items[1] 2 front=1
items[0] 1
Remove items from circular queue
• Remove one more item from the queue.
items[6]
items[5]
items[4]
items[3]
items[2] 3 rear=front=2
items[1] 2
items[0] 1
Insert operation in Circular Queue:
Overcome Drawback of Linear Queue
• Insert 4,5,6,7 to the queue.
items[6] 7 rear=6
items[5] 6
items[4] 5
items[3] 4
items[2] 3 front=2
items[1] 2
items[0] 1
Insert operation in Circular Queue:
Overcome Drawback of Linear Queue
• Insert 8 and 9 to the queue.
items[6] 7
items[5] 6
items[4] 5
items[3] 4
items[2] 3 front=2
items[1] 2
items[0] 8 rear=0
Insert operation in Circular Queue:
Overcome Drawback of Linear Queue
• Insert 8 and 9 to the queue.
items[6] 7
items[5] 6
items[4] 5
items[3] 4
items[2] 3 front=2
items[1] 9
items[0] 8 rear=0
Insert operation in Circular Queue:
Overcome Drawback of Linear Queue
• Insert 10 to the queue.
items[6] 7
items[5] 6
items[4] 5
items[3] 4
items[2] ?? front=rear=2
items[1] 9
items[0] 8
Implementation of a Circular Queue in C
#define MAX 10 /* size of the queue items*/
typedef struct {
int front;
int rear;
int items[MAX];
}QUEUE;
QUEUE Q;
Q.front = MAX-1;
Q.rear= MAX-1;
EMPTY QUEUE
[2] [3] [2] [3]
[1] [4] [1] [4]
[0] [5] [0] [5]
front = 0 front = 0
rear = 0 rear = 3
B
A
C
Implementation 2:Cyclic View
Can be seen as a circular queue
FULL QUEUE FULL QUEUE
[2] [3] [2] [3]
[1] [4][1] [4]
[0] [5] [0] [5]
front =0
rear = 5
front =4
rear =3
B C
A D
E F E
G
H I
Advantage of Circular Queue:
How to test when queue is UNDERFLOW?
How to test when queue is OVERFLOW?
Implementation of Insert Operation for
Circular Queue in C
void insert(QUEUE *qptr, char x)
{
if(qptr->rear == MAX-1)
qptr->rear=0;
else
qptr->rear++;
/* or qptr->rear=(qptr->rear+1)%MAX) */
if(qptr->rear == qptr->front){
printf("Queue overflow");
exit(1);
}
qptr->items[qptr->rear]=x;
}
Implementation of Remove Operation
for Circular Queue in C
char remove(struct queue *qptr)
{
if(qptr->front == qptr->rear){
printf("Queue underflow");
exit(1);
}
if(qptr->front == MAX-1)
qptr->front=0;
else
qptr->front++;
return qptr->items[qptr->front];
}
#include <stdlib.h>
#include <stdio.h>
#define MAX 50
#define TRUE 1
#define FALSE 0
typedef struct
{
int items[MAX];
int front , rear ;
} Q;
void queinsert( Q * , int);
int quedelete(Q *);
int isempty(Q *);
EXAMPLE in C
int main()
{
char operation;
int x;
Q q;
q.front = q.rear = MAX - 1;
do
{
printf("%sn",“Queue Operation type I(Insert) D(Delete) or E(Exit) ");
scanf("n%c",&choice);
switch (choice) {
case 'I’: printf("%sn","Insert an element");
scanf("n%d",&x);
qinsert(&q , x);
break;
case 'D’: x=qdelete(&q);
printf("n %d is deleted n",x);
break;
default: printf(“Incorrect Operation typen”);
break;
}
}
while (choice != 'E’&&choice!='e');
return 0;
}
int isempty(Q *qptr)
{
return((qptr->front == qptr->rear) ? TRUE : FALSE);
}
int qdelete(Q *qptr)
{
if (empty(qptr)) {
printf("Queue underflow ");
exit(1);
}
qptr->front=(qptr->front+1)%(MAX)
return(qptr->items[qptr->front]);
}
void qinsert(Q *qptr , int x)
{
/* make room for new element */
printf("n %d is inserted n",x);
qptr->rear=(qptr->rear+1)%(MAX)
if (qptr->rear == qptr->front) {
printf("Queue overflow");
exit(1);
}
qptr->items[qptr->rear] = x;
return;
}
#include<stdio.h>
#include<stdlib.h>
#define MAX 5 /* size of the queue items*/
typedef struct{
int front;
int rear;
float items[MAX];
}Q;
void qinsert(Q *, float);
float qdelete(Q *);
void display( Q *);
void clear( Q *);
void menu();
int main()
{
int choice;
float x;
Q q;
q.front = M-1;
q.rear= MAX-1;
do{
menu();
scanf("%d",&choice);
switch(choice){
case 1: printf("Enter the item to be inserted:");
scanf("%f",&x);
insert(&q,x);
break;
case 2: x=remove(&q); printf("nRemoved item:%f",x);
break;
case 3: display(&q);
break;
case 4: clear(&q);
break;
default: printf("nWrong entry, Try again!!");
break;
}
}while(choice != 5);
return 0;
}
void menu()
{
printf("Press 1 to insert n");
printf("Press 2 to remove n");
printf("Press 3 to display n");
printf("Press 4 to clear n");
printf("Press 5 to quitn");
printf("nnEnter your choice:n");
}
void insert(q *qptr, float x)
{
if(qptr->rear == MAXQ-1)
qptr->rear=0;
else
qptr->rear++;
if(qptr->rear == qptr->front){
printf("Queue overflow");
exit(1);
}
qptr->items[qptr->rear]=x;
}
float remove(q *qptr)
{
if(qptr->front == qptr->rear){
printf("Queue underflow");
exit(1);
}
if(qptr->front == MAX-1)
qptr->front=0;
else
qptr->front++;
return qptr->items[qptr->front];
}
void clear(q *qptr)
{
qptr->front=MAX-1;
qptr->rear =MAX-1;
printf("Now the Queue is Emptyn");
}
void display(q *qptr)
{
int f,r;
f=qptr->front;
r=qptr->rear;
while(qptr->front !=qptr->rear){
if(qptr->front == MAX-1)
qptr->front =0;
else
qptr->front++;
printf("%5.2f",qptr->items[qptr->front]);
}
printf("n");
qptr->front=f;
qptr->rear=r;
}
typedef struct{
int front;
int rear;
int items[MAX]; /* Assume that MAX SIZE is
defined*/
}Q;
Case Study for Queue Search Element
int QSearch(Q *qptr, int search)
{
int pos = -1,f;
f=qptr->front;
while(qptr->front !=qptr->rear){
if(qptr->front == MAX-1)
qptr->front =0;
else
qptr->front++;
if(qptr->items[qptr->front] == search){
pos = qptr->front;
qptr->front = f;
return pos;
}
}
qptr->front=f;
return pos;
}
Implementation in C:
Case Study in Queue: Copy Reverse
typedef struct{
int front;
int rear;
int items[MAX]; /* Assume that MAX SIZE is
defined*/
}Q;
void QCopyReverse(Q *qptr1, Q *qptr2)
{
int r,item;
r=qptr1->rear;
do{
item = qptr1->items[qptr1->rear];
insert(qptr2,item);
if(qptr1->rear ==0)
qptr1->rear = MAX-1;
else
qptr1->rear --;
}while(qptr1->rear != qptr1->front);
qptr1->rear = r;
}
void insert(Q *qptr, int item)
{
if(qptr->rear == MAX-1)
qptr->rear=0;
else
qptr->rear++;
if(qptr->rear == qptr->front){
printf("Queue overflow");
exit(1);
}
qptr->items[qptr->rear]=item;
}
PRIORITY QUEUES
• The priority queue is a data structure in which internally
ordering of the elements determines the results of its basic
operations.
• An ascending priority queue is a combination of items with
priority into which items can be inserted arbitrarily and from
which only the smallest item can be removed. On the other
hand a descending priority queue allows only the largest item to
be removed.
• We use process.h for operation.
Priority QUEUE Operations
• Insertion
• The insertion in Priority queues is the same as in non-priority
queues.
• Deletion
• Deletion requires a search for the element of highest priority
and deletes the element with highest priority. The following
methods can be used for deletion/removal from a given
Priority Queue:
• An empty indicator replaces deleted elements.
• After each deletion elements can be moved up in the array
decrementing the rear.
• The array in the queue can be maintained as an ordered
circular array
Priority Queues Features
• Specialized data structure.
• Same as Queue, having front and rear.
• Items are deleted from the front.
• Items are ordered by priority value so that the item
with the lowest key (or highest) is always at the
front.
• Items are inserted in proper position to maintain
the order of ascending or descending.
Priority Queue : Class Diagram
+Queue()
+insert() : void
+remove() : long
+peekMin() : long
+isEmpty() : bool
+isFull() : bool
-maxSize : int
-queueArray [] : long
-nItems : int
PrioityQ
PriorityQApp
Interface1
Priority Queue Implementation in C
#define MAX 10 /* size of the queue items*/
typedef struct {
int front, rear;
int items[MAX];
}PQ;
int PQremove(Q *qptr)
{
int small, loc, f, i;
f=qptr->front;
if(qptr->front == qptr->rear){
printf("Queue underflow");
exit(1);
}
small = qptr->items[(qptr->front+1)%MAX];
loc = (qptr->front+1)%MAX;
(qptr->front++)%MAX; /* Circular increment*/
while(qptr->front != qptr->rear){
if(qptr->items[(qptr->front+1)%MAX] <small){
small = qptr->items[(qptr->front+1)%MAX];
loc = (qptr->front+1)%MAX;
}
qptr->front =(qptr->front+1)%MAX;
}
while(loc != qptr->rear){
qptr->items[loc] = qptr->items[(loc+1)%MAX];
(loc++)%MAX;
}
qptr->front=f;
if(qptr->rear == 0) /*Decrement rear after removing one
item*/
qptr->rear = MAX -1;
else
qptr->rear--;
return smallest;
}
Insert Operation of Priority Queue implemented in C
void insert(struct q *qptr, int item)
{
qptr->rear = (qptr->rear++)%MAX; /*Circular
increment*/
if(qptr->rear == qptr->front){
printf("Queue overflow");
exit(1);
}
qptr->items[qptr->rear]=item;
}
void enqueue(pqnode front, pqnode rear, element x)
{
pqnode temp =(pqnode) malloc(sizeof (queue));
if (IS_FULL(temp))
{
printf(“ The memory is fulln”);
exit(1);
}
temp->data = x;
temp->next= NULL;
if (front) { (rear) -> next= temp;}
else front = temp;
rear = temp;
Case Study: List-based Queue Implementation in C: insertion
int dequeue(pqnode front)
{
pqnode temp = front;
int x;
if (IS_EMPTY(front))
{
printf(“The queue is emptyn”);
exit(1);
}
x = temp->data;
front = temp->next;
free(temp);
return x;
}
Case Study: List-based Queue
Implementation in C: Deletion
Stack vs. Queue vs. Array
• Stack & Queue vs. Array
• Arrays are homogeneous data storage structures while
stacks and queues are derived ADT data storage
structures.
• Stack – ADT that allows push, peep and pop.
• Queue - ADT that allows enqueue and dequeue.
• In an array any item can be accessed through
index, while in these data structures access is
restricted.
Real world example of Queue
<?xml version = "1.0"?>
<!-- An author -->
<author>
<name gender = "male">
<first> Art </first>
<last> Gentleman </last>
</name>
</author>
THANK YOU
GIVE FEEDBACK

More Related Content

What's hot

Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
Ashim Lamichhane
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examplesgreatqadirgee4u
 
Em simulator hfss_metamaterial
Em simulator hfss_metamaterialEm simulator hfss_metamaterial
Em simulator hfss_metamaterial
atlantic sky
 
Reflectarray antenna [Antenna]
Reflectarray antenna [Antenna]Reflectarray antenna [Antenna]
Reflectarray antenna [Antenna]
Ethar Sayed
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
Soumen Santra
 
array
array array
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
Arpana shree
 
fourier transform of DT signals
fourier transform of DT signalsfourier transform of DT signals
fourier transform of DT signals
tejaspatel1998
 
K map.
K map.K map.
Chapter 4 strings
Chapter 4 stringsChapter 4 strings
Chapter 4 strings
Chv Raghavendran
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
Rajendran
 
Antenna array
Antenna arrayAntenna array
Antenna array
yonas yifter
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentation
VedaGayathri1
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdf
omprakashmeena48
 
Horn antennas
Horn antennasHorn antennas
Horn antennas
ramalakshmi54
 
Antenna slide
Antenna slideAntenna slide
Antenna slide
Shahidul Islam Himel
 
Manipulators
ManipulatorsManipulators
Manipulators
VaishnaviVaishnavi17
 
Radar fundamentals
Radar fundamentalsRadar fundamentals
Radar fundamentals
Hossam Zein
 

What's hot (20)

Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
Em simulator hfss_metamaterial
Em simulator hfss_metamaterialEm simulator hfss_metamaterial
Em simulator hfss_metamaterial
 
Reflectarray antenna [Antenna]
Reflectarray antenna [Antenna]Reflectarray antenna [Antenna]
Reflectarray antenna [Antenna]
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
array
array array
array
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
fourier transform of DT signals
fourier transform of DT signalsfourier transform of DT signals
fourier transform of DT signals
 
K map.
K map.K map.
K map.
 
Chapter 4 strings
Chapter 4 stringsChapter 4 strings
Chapter 4 strings
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Antenna array
Antenna arrayAntenna array
Antenna array
 
ThereminReport
ThereminReportThereminReport
ThereminReport
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentation
 
STRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdfSTRING LIST TUPLE DICTIONARY FILE.pdf
STRING LIST TUPLE DICTIONARY FILE.pdf
 
Horn antennas
Horn antennasHorn antennas
Horn antennas
 
microwave_antenna
microwave_antennamicrowave_antenna
microwave_antenna
 
Antenna slide
Antenna slideAntenna slide
Antenna slide
 
Manipulators
ManipulatorsManipulators
Manipulators
 
Radar fundamentals
Radar fundamentalsRadar fundamentals
Radar fundamentals
 

Similar to Queues & ITS TYPES

Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
Dabbal Singh Mahara
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
MuhammadUmerIhtisham
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
Tribhuvan University
 
QUEUES
QUEUESQUEUES
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
Mandeep Singh
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
shaik faroq
 
Queue
QueueQueue
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
singhprpg
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
Toseef Hasan
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
NuraMohamed9
 
Queue
QueueQueue
Queue
QueueQueue
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms Queues
ManishPrajapati78
 
Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
btechsmartclass
 
basics of queues
basics of queuesbasics of queues
basics of queues
sirmanohar
 

Similar to Queues & ITS TYPES (20)

Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
QUEUES
QUEUESQUEUES
QUEUES
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
Queue
QueueQueue
Queue
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
 
Queue
QueueQueue
Queue
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms Queues
 
Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
 
basics of queues
basics of queuesbasics of queues
basics of queues
 

More from Soumen Santra

Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Cell hole identification in carcinogenic segment using Geodesic Methodology: ...
Cell hole identification in carcinogenic segment using Geodesic Methodology: ...Cell hole identification in carcinogenic segment using Geodesic Methodology: ...
Cell hole identification in carcinogenic segment using Geodesic Methodology: ...
Soumen Santra
 
PPT_PAPERID 31_SOUMEN_SANTRA - ICCET23.pptx
PPT_PAPERID 31_SOUMEN_SANTRA - ICCET23.pptxPPT_PAPERID 31_SOUMEN_SANTRA - ICCET23.pptx
PPT_PAPERID 31_SOUMEN_SANTRA - ICCET23.pptx
Soumen Santra
 
Basic networking hardware: Switch : Router : Hub : Bridge : Gateway : Bus : C...
Basic networking hardware: Switch : Router : Hub : Bridge : Gateway : Bus : C...Basic networking hardware: Switch : Router : Hub : Bridge : Gateway : Bus : C...
Basic networking hardware: Switch : Router : Hub : Bridge : Gateway : Bus : C...
Soumen Santra
 
Traveling salesman problem: Game Scheduling Problem Solution: Ant Colony Opti...
Traveling salesman problem: Game Scheduling Problem Solution: Ant Colony Opti...Traveling salesman problem: Game Scheduling Problem Solution: Ant Colony Opti...
Traveling salesman problem: Game Scheduling Problem Solution: Ant Colony Opti...
Soumen Santra
 
Optimization techniques: Ant Colony Optimization: Bee Colony Optimization: Tr...
Optimization techniques: Ant Colony Optimization: Bee Colony Optimization: Tr...Optimization techniques: Ant Colony Optimization: Bee Colony Optimization: Tr...
Optimization techniques: Ant Colony Optimization: Bee Colony Optimization: Tr...
Soumen Santra
 
Quick Sort
Quick SortQuick Sort
Quick Sort
Soumen Santra
 
Merge sort
Merge sortMerge sort
Merge sort
Soumen Santra
 
A Novel Real Time Home Automation System with Google Assistance Technology
A Novel Real Time Home Automation System with Google Assistance TechnologyA Novel Real Time Home Automation System with Google Assistance Technology
A Novel Real Time Home Automation System with Google Assistance Technology
Soumen Santra
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Soumen Santra
 
Java Basic PART I
Java Basic PART IJava Basic PART I
Java Basic PART I
Soumen Santra
 
Threads Advance in System Administration with Linux
Threads Advance in System Administration with LinuxThreads Advance in System Administration with Linux
Threads Advance in System Administration with Linux
Soumen Santra
 
Frequency Division Multiplexing Access (FDMA)
Frequency Division Multiplexing Access (FDMA)Frequency Division Multiplexing Access (FDMA)
Frequency Division Multiplexing Access (FDMA)
Soumen Santra
 
Carrier Sense Multiple Access With Collision Detection (CSMA/CD) Details : Me...
Carrier Sense Multiple Access With Collision Detection (CSMA/CD) Details : Me...Carrier Sense Multiple Access With Collision Detection (CSMA/CD) Details : Me...
Carrier Sense Multiple Access With Collision Detection (CSMA/CD) Details : Me...
Soumen Santra
 
Code-Division Multiple Access (CDMA)
Code-Division Multiple Access (CDMA)Code-Division Multiple Access (CDMA)
Code-Division Multiple Access (CDMA)
Soumen Santra
 
PURE ALOHA : MEDIUM ACCESS CONTROL PROTOCOL (MAC): Definition : Types : Details
PURE ALOHA : MEDIUM ACCESS CONTROL PROTOCOL (MAC): Definition : Types : DetailsPURE ALOHA : MEDIUM ACCESS CONTROL PROTOCOL (MAC): Definition : Types : Details
PURE ALOHA : MEDIUM ACCESS CONTROL PROTOCOL (MAC): Definition : Types : Details
Soumen Santra
 
Carrier-sense multiple access with collision avoidance CSMA/CA
Carrier-sense multiple access with collision avoidance CSMA/CACarrier-sense multiple access with collision avoidance CSMA/CA
Carrier-sense multiple access with collision avoidance CSMA/CA
Soumen Santra
 
RFID (RADIO FREQUENCY IDENTIFICATION)
RFID (RADIO FREQUENCY IDENTIFICATION)RFID (RADIO FREQUENCY IDENTIFICATION)
RFID (RADIO FREQUENCY IDENTIFICATION)
Soumen Santra
 
SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION
SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION  SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION
SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION
Soumen Santra
 
Threads Basic : Features, Types & Implementation
Threads Basic : Features, Types  & ImplementationThreads Basic : Features, Types  & Implementation
Threads Basic : Features, Types & Implementation
Soumen Santra
 

More from Soumen Santra (20)

Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Cell hole identification in carcinogenic segment using Geodesic Methodology: ...
Cell hole identification in carcinogenic segment using Geodesic Methodology: ...Cell hole identification in carcinogenic segment using Geodesic Methodology: ...
Cell hole identification in carcinogenic segment using Geodesic Methodology: ...
 
PPT_PAPERID 31_SOUMEN_SANTRA - ICCET23.pptx
PPT_PAPERID 31_SOUMEN_SANTRA - ICCET23.pptxPPT_PAPERID 31_SOUMEN_SANTRA - ICCET23.pptx
PPT_PAPERID 31_SOUMEN_SANTRA - ICCET23.pptx
 
Basic networking hardware: Switch : Router : Hub : Bridge : Gateway : Bus : C...
Basic networking hardware: Switch : Router : Hub : Bridge : Gateway : Bus : C...Basic networking hardware: Switch : Router : Hub : Bridge : Gateway : Bus : C...
Basic networking hardware: Switch : Router : Hub : Bridge : Gateway : Bus : C...
 
Traveling salesman problem: Game Scheduling Problem Solution: Ant Colony Opti...
Traveling salesman problem: Game Scheduling Problem Solution: Ant Colony Opti...Traveling salesman problem: Game Scheduling Problem Solution: Ant Colony Opti...
Traveling salesman problem: Game Scheduling Problem Solution: Ant Colony Opti...
 
Optimization techniques: Ant Colony Optimization: Bee Colony Optimization: Tr...
Optimization techniques: Ant Colony Optimization: Bee Colony Optimization: Tr...Optimization techniques: Ant Colony Optimization: Bee Colony Optimization: Tr...
Optimization techniques: Ant Colony Optimization: Bee Colony Optimization: Tr...
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
A Novel Real Time Home Automation System with Google Assistance Technology
A Novel Real Time Home Automation System with Google Assistance TechnologyA Novel Real Time Home Automation System with Google Assistance Technology
A Novel Real Time Home Automation System with Google Assistance Technology
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
 
Java Basic PART I
Java Basic PART IJava Basic PART I
Java Basic PART I
 
Threads Advance in System Administration with Linux
Threads Advance in System Administration with LinuxThreads Advance in System Administration with Linux
Threads Advance in System Administration with Linux
 
Frequency Division Multiplexing Access (FDMA)
Frequency Division Multiplexing Access (FDMA)Frequency Division Multiplexing Access (FDMA)
Frequency Division Multiplexing Access (FDMA)
 
Carrier Sense Multiple Access With Collision Detection (CSMA/CD) Details : Me...
Carrier Sense Multiple Access With Collision Detection (CSMA/CD) Details : Me...Carrier Sense Multiple Access With Collision Detection (CSMA/CD) Details : Me...
Carrier Sense Multiple Access With Collision Detection (CSMA/CD) Details : Me...
 
Code-Division Multiple Access (CDMA)
Code-Division Multiple Access (CDMA)Code-Division Multiple Access (CDMA)
Code-Division Multiple Access (CDMA)
 
PURE ALOHA : MEDIUM ACCESS CONTROL PROTOCOL (MAC): Definition : Types : Details
PURE ALOHA : MEDIUM ACCESS CONTROL PROTOCOL (MAC): Definition : Types : DetailsPURE ALOHA : MEDIUM ACCESS CONTROL PROTOCOL (MAC): Definition : Types : Details
PURE ALOHA : MEDIUM ACCESS CONTROL PROTOCOL (MAC): Definition : Types : Details
 
Carrier-sense multiple access with collision avoidance CSMA/CA
Carrier-sense multiple access with collision avoidance CSMA/CACarrier-sense multiple access with collision avoidance CSMA/CA
Carrier-sense multiple access with collision avoidance CSMA/CA
 
RFID (RADIO FREQUENCY IDENTIFICATION)
RFID (RADIO FREQUENCY IDENTIFICATION)RFID (RADIO FREQUENCY IDENTIFICATION)
RFID (RADIO FREQUENCY IDENTIFICATION)
 
SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION
SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION  SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION
SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION
 
Threads Basic : Features, Types & Implementation
Threads Basic : Features, Types  & ImplementationThreads Basic : Features, Types  & Implementation
Threads Basic : Features, Types & Implementation
 

Recently uploaded

RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 

Recently uploaded (20)

RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 

Queues & ITS TYPES

  • 2. DEFINITION OF QUEUE • A Queue is an ordered collection ADT(Abstract Data Type) of items from which items may be deleted at one end (FRONT) and into which items may be inserted at the other end (REAR). • The first element inserted into the queue is the first element to be removed. The queue is sometimes called a FIFO (first-in first-out) list as opposed to the stack, which is a LIFO (last-in first-out).
  • 3. Queue • Stores a set of elements in a particular order • Stack principle: FIRST IN FIRST OUT • = FIFO • It means: the first element inserted is the first one to be removed. • The first one in line is the first one to be served • Example
  • 4. Queue Applications • Real life examples • Waiting in line for reservation • Waiting on hold for tech support • Applications related to Computer Science • Threads scheduling & synchronization • Job scheduling (e.g. Round-Robin algorithm for CPU allocation)
  • 6. front rear Q[0] Q[1] Q[2] Q[3] Comments -1 -1 -1 -1 0 1 -1 0 1 2 2 2 J1 J1 J2 J1 J2 J3 J2 J3 J3 queue is empty Job 1 is added Job 2 is added Job 3 is added Job 1 is deleted Job 2 is deleted Applications: Job Scheduling
  • 7. Queue items[MAX-1] . . . . . . items[2] C items[1] B items[0] A Front=0 Rear=2
  • 8. Declaration of a Queue # define MAX 500 /* size of the queue items*/ typedef struct { int front; int rear; int items[MAX]; }QUEUE;
  • 9. QUEUE OPERATIONS • Initialize the queue • Insert to the rear of the queue • Remove (Delete) from the front of the queue • Is the Queue Empty • Is the Queue Full • What is the size of the Queue
  • 10. Queue Example: Class Diagram Concept +Queue() +insert() : void +remove() : long +peekFront() : long +isEmpty() : bool +isFull() : bool +size() : int -maxSize : int -queueArray [] : long -front : int -rear : int -nItems : int Queue QueueApp Interface1
  • 11. INITIALIZE THE QUEUE items[MAX-1] . . . . . items[1] items[0] front=0 rear=-1 •The queue is initialized by having the rear set to -1, and front set to 0. Let us assume that maximum number of the element we have in a queue is MAX size elements as shown below.
  • 12. insert(&Queue, ‘A’) Method • an item (A) is inserted at the Rear of the queue items[MAX-1] . . . . items[3] items[2] items[1] items[0] A Front=0, Rear=0
  • 13. insert(&Queue, ‘B’) Method • A new item (B) is inserted at the Rear of the queue items[MAX-1] . . . . items[3] items[2] items[1] B Rear=1 items[0] A Front=0
  • 14. insert(&Queue, ‘C’) Method • A new item (C) is inserted at the Rear of the queue items[MAX-1] . . . . items[3] items[2] C Rear=2 items[1] B items[0] A Front=0
  • 15. insert(&Queue, ‘D’) Method • A new item (D) is inserted at the Rear of the queue items[MAX-1] . . . . items[3] D Rear=3 items[2] C items[1] B items[0] A Front=0
  • 16. Array-based Queue Implementation • As with the array-based stack implementation, the array is of fixed size • A queue of maximum N elements • Slightly more complicated • Need to maintain CONTROL of both front and rear Implementation 1 Implementation 2
  • 17. Insert Operation of Queue using pointer void insert(QUEUE *qptr, char x) { if(qptr->rear == MAX-1) { printf("Queue is full!"); exit(1); } else { qptr->rear++; qptr->items[qptr->rear]=x; } }
  • 18. char remove(&Queue) Method • an item (A) is removed (deleted) from the Front of the queue & return it as per datatype. items[MAX-1] . . . . items[3] D Rear=3 items[2] C items[1] B Front=1 items[0] A
  • 19. char remove(&Queue) Method • Remove two items from the front of the queue. items[MAX-1] . . . . items[3] D Rear=3 items[2] C Front=2 items[1] B items[0] A
  • 20. char remove(&Queue) Method • Remove two items from the front of the queue. items[MAX-1] . . . . items[3] D Front=Rear=3 items[2] C items[1] B items[0] A
  • 21. char remove(&Queue) Method • Remove one more item from the front of the queue. items[MAX-1] . . items[4] Front=4 items[3] D Rear=3 items[2] C items[1] B items[0] A
  • 22. Remove Operation implementation in c char remove(struct queue *qptr) { char p; if(qptr->front > qptr->rear){ printf("Queue is empty"); exit(1); } else {p=qptr->items[qptr->front]; qptr->front++; return p; } }
  • 23. INSERT / REMOVE ITEMS : Drawback of Linear Queue • Assume that the rear= MAX-1 •What happens if we want to insert a new item into the queue? items[MAX-1] X rear=MAX-1 . . . . items[3] D front=3 items[2] C items[1] B items[0] A
  • 24. INSERT / REMOVE ITEMS • What happens if we want to insert a new item F into the queue? • Although there is some empty space, the queue is full. • One of the methods to overcome this problem is to shift all the items to occupy the location of deleted item.
  • 25. REMOVE ITEM items[MAX-1] . . . . items[3] D Rear=3 items[2] C items[1] B Front=1 items[0] A
  • 26. REMOVE ITEM : Example items[MAX-1] . . . . items[3] D Rear=3 items[2] C items[1] B Front=1 items[0] B
  • 27. REMOVE ITEM : Example items[MAX-1] . . . . items[3] D Rear=3 items[2] C items[1] C items[0] B
  • 28. REMOVE ITEM : Example items[MAX-1] . . . . items[3] D Rear=3 items[2] D items[1] C items[0] B
  • 29. REMOVE ITEM : Example items[MAX-1] . . . . items[3] D items[2] D Rear=2 items[1] C items[0] B
  • 30. Modified Remove Operation implementation in C char remove(struct queue *qptr) { char p; int i; if(qptr->front > qptr->rear){ printf("Queue is empty"); exit(1); } else {p=qptr->items[qptr->front]; for(i=1;i<=qptr->rear;i++) qptr->items[i-1]=qptr->items[i]; qptr->rear-- return p; } }
  • 31. INSERT / REMOVE ITEMS • Since all the items in the queue are required to shift when an item is deleted, this method is not preferred. • The other method is circular queue. • When rear = MAX-1, the next element is entered at items[0] in case that spot is free.
  • 32. How to Initialize the queue items[6] front=rear=6 items[5] items[4] items[3] items[2] items[1] items[0]
  • 33. Insert operation in Circular Queue items[6] front=6 items[5] items[4] items[3] items[2] items[1] items[0] 1 rear=0  Insert 1,2,3 to the rear of the queue.
  • 34. Insert operation in Circular Queue items[6] front=6 items[5] items[4] items[3] items[2] items[1] 2 rear=1 items[0] 1  Insert 1,2,3 to the rear of the queue.
  • 35. Insert operation in Circular Queue • Insert 1,2,3 to the rear of the queue. items[6] front=6 items[5] items[4] items[3] items[2] 3 rear=2 items[1] 2 items[0] 1
  • 36. Remove items from circular queue • Remove two items from the queue. items[6] items[5] items[4] items[3] items[2] 3 rear=2 items[1] 2 items[0] 1 front=0
  • 37. Remove items from circular queue • Remove two items from the queue. items[6] items[5] items[4] items[3] items[2] 3 rear=2 items[1] 2 front=1 items[0] 1
  • 38. Remove items from circular queue • Remove one more item from the queue. items[6] items[5] items[4] items[3] items[2] 3 rear=front=2 items[1] 2 items[0] 1
  • 39. Insert operation in Circular Queue: Overcome Drawback of Linear Queue • Insert 4,5,6,7 to the queue. items[6] 7 rear=6 items[5] 6 items[4] 5 items[3] 4 items[2] 3 front=2 items[1] 2 items[0] 1
  • 40. Insert operation in Circular Queue: Overcome Drawback of Linear Queue • Insert 8 and 9 to the queue. items[6] 7 items[5] 6 items[4] 5 items[3] 4 items[2] 3 front=2 items[1] 2 items[0] 8 rear=0
  • 41. Insert operation in Circular Queue: Overcome Drawback of Linear Queue • Insert 8 and 9 to the queue. items[6] 7 items[5] 6 items[4] 5 items[3] 4 items[2] 3 front=2 items[1] 9 items[0] 8 rear=0
  • 42. Insert operation in Circular Queue: Overcome Drawback of Linear Queue • Insert 10 to the queue. items[6] 7 items[5] 6 items[4] 5 items[3] 4 items[2] ?? front=rear=2 items[1] 9 items[0] 8
  • 43. Implementation of a Circular Queue in C #define MAX 10 /* size of the queue items*/ typedef struct { int front; int rear; int items[MAX]; }QUEUE; QUEUE Q; Q.front = MAX-1; Q.rear= MAX-1;
  • 44. EMPTY QUEUE [2] [3] [2] [3] [1] [4] [1] [4] [0] [5] [0] [5] front = 0 front = 0 rear = 0 rear = 3 B A C Implementation 2:Cyclic View Can be seen as a circular queue
  • 45. FULL QUEUE FULL QUEUE [2] [3] [2] [3] [1] [4][1] [4] [0] [5] [0] [5] front =0 rear = 5 front =4 rear =3 B C A D E F E G H I Advantage of Circular Queue: How to test when queue is UNDERFLOW? How to test when queue is OVERFLOW?
  • 46. Implementation of Insert Operation for Circular Queue in C void insert(QUEUE *qptr, char x) { if(qptr->rear == MAX-1) qptr->rear=0; else qptr->rear++; /* or qptr->rear=(qptr->rear+1)%MAX) */ if(qptr->rear == qptr->front){ printf("Queue overflow"); exit(1); } qptr->items[qptr->rear]=x; }
  • 47. Implementation of Remove Operation for Circular Queue in C char remove(struct queue *qptr) { if(qptr->front == qptr->rear){ printf("Queue underflow"); exit(1); } if(qptr->front == MAX-1) qptr->front=0; else qptr->front++; return qptr->items[qptr->front]; }
  • 48. #include <stdlib.h> #include <stdio.h> #define MAX 50 #define TRUE 1 #define FALSE 0 typedef struct { int items[MAX]; int front , rear ; } Q; void queinsert( Q * , int); int quedelete(Q *); int isempty(Q *); EXAMPLE in C
  • 49. int main() { char operation; int x; Q q; q.front = q.rear = MAX - 1; do { printf("%sn",“Queue Operation type I(Insert) D(Delete) or E(Exit) "); scanf("n%c",&choice); switch (choice) { case 'I’: printf("%sn","Insert an element"); scanf("n%d",&x); qinsert(&q , x); break; case 'D’: x=qdelete(&q); printf("n %d is deleted n",x); break; default: printf(“Incorrect Operation typen”); break; } } while (choice != 'E’&&choice!='e'); return 0; }
  • 50. int isempty(Q *qptr) { return((qptr->front == qptr->rear) ? TRUE : FALSE); } int qdelete(Q *qptr) { if (empty(qptr)) { printf("Queue underflow "); exit(1); } qptr->front=(qptr->front+1)%(MAX) return(qptr->items[qptr->front]); } void qinsert(Q *qptr , int x) { /* make room for new element */ printf("n %d is inserted n",x); qptr->rear=(qptr->rear+1)%(MAX) if (qptr->rear == qptr->front) { printf("Queue overflow"); exit(1); } qptr->items[qptr->rear] = x; return; }
  • 51. #include<stdio.h> #include<stdlib.h> #define MAX 5 /* size of the queue items*/ typedef struct{ int front; int rear; float items[MAX]; }Q; void qinsert(Q *, float); float qdelete(Q *); void display( Q *); void clear( Q *); void menu();
  • 52. int main() { int choice; float x; Q q; q.front = M-1; q.rear= MAX-1; do{ menu(); scanf("%d",&choice); switch(choice){ case 1: printf("Enter the item to be inserted:"); scanf("%f",&x); insert(&q,x); break; case 2: x=remove(&q); printf("nRemoved item:%f",x); break; case 3: display(&q); break; case 4: clear(&q); break; default: printf("nWrong entry, Try again!!"); break; } }while(choice != 5); return 0; }
  • 53. void menu() { printf("Press 1 to insert n"); printf("Press 2 to remove n"); printf("Press 3 to display n"); printf("Press 4 to clear n"); printf("Press 5 to quitn"); printf("nnEnter your choice:n"); } void insert(q *qptr, float x) { if(qptr->rear == MAXQ-1) qptr->rear=0; else qptr->rear++; if(qptr->rear == qptr->front){ printf("Queue overflow"); exit(1); } qptr->items[qptr->rear]=x; }
  • 54. float remove(q *qptr) { if(qptr->front == qptr->rear){ printf("Queue underflow"); exit(1); } if(qptr->front == MAX-1) qptr->front=0; else qptr->front++; return qptr->items[qptr->front]; } void clear(q *qptr) { qptr->front=MAX-1; qptr->rear =MAX-1; printf("Now the Queue is Emptyn"); }
  • 55. void display(q *qptr) { int f,r; f=qptr->front; r=qptr->rear; while(qptr->front !=qptr->rear){ if(qptr->front == MAX-1) qptr->front =0; else qptr->front++; printf("%5.2f",qptr->items[qptr->front]); } printf("n"); qptr->front=f; qptr->rear=r; }
  • 56. typedef struct{ int front; int rear; int items[MAX]; /* Assume that MAX SIZE is defined*/ }Q; Case Study for Queue Search Element
  • 57. int QSearch(Q *qptr, int search) { int pos = -1,f; f=qptr->front; while(qptr->front !=qptr->rear){ if(qptr->front == MAX-1) qptr->front =0; else qptr->front++; if(qptr->items[qptr->front] == search){ pos = qptr->front; qptr->front = f; return pos; } } qptr->front=f; return pos; } Implementation in C:
  • 58. Case Study in Queue: Copy Reverse typedef struct{ int front; int rear; int items[MAX]; /* Assume that MAX SIZE is defined*/ }Q;
  • 59. void QCopyReverse(Q *qptr1, Q *qptr2) { int r,item; r=qptr1->rear; do{ item = qptr1->items[qptr1->rear]; insert(qptr2,item); if(qptr1->rear ==0) qptr1->rear = MAX-1; else qptr1->rear --; }while(qptr1->rear != qptr1->front); qptr1->rear = r; } void insert(Q *qptr, int item) { if(qptr->rear == MAX-1) qptr->rear=0; else qptr->rear++; if(qptr->rear == qptr->front){ printf("Queue overflow"); exit(1); } qptr->items[qptr->rear]=item; }
  • 60. PRIORITY QUEUES • The priority queue is a data structure in which internally ordering of the elements determines the results of its basic operations. • An ascending priority queue is a combination of items with priority into which items can be inserted arbitrarily and from which only the smallest item can be removed. On the other hand a descending priority queue allows only the largest item to be removed. • We use process.h for operation.
  • 61. Priority QUEUE Operations • Insertion • The insertion in Priority queues is the same as in non-priority queues. • Deletion • Deletion requires a search for the element of highest priority and deletes the element with highest priority. The following methods can be used for deletion/removal from a given Priority Queue: • An empty indicator replaces deleted elements. • After each deletion elements can be moved up in the array decrementing the rear. • The array in the queue can be maintained as an ordered circular array
  • 62. Priority Queues Features • Specialized data structure. • Same as Queue, having front and rear. • Items are deleted from the front. • Items are ordered by priority value so that the item with the lowest key (or highest) is always at the front. • Items are inserted in proper position to maintain the order of ascending or descending.
  • 63. Priority Queue : Class Diagram +Queue() +insert() : void +remove() : long +peekMin() : long +isEmpty() : bool +isFull() : bool -maxSize : int -queueArray [] : long -nItems : int PrioityQ PriorityQApp Interface1
  • 64. Priority Queue Implementation in C #define MAX 10 /* size of the queue items*/ typedef struct { int front, rear; int items[MAX]; }PQ;
  • 65. int PQremove(Q *qptr) { int small, loc, f, i; f=qptr->front; if(qptr->front == qptr->rear){ printf("Queue underflow"); exit(1); } small = qptr->items[(qptr->front+1)%MAX]; loc = (qptr->front+1)%MAX; (qptr->front++)%MAX; /* Circular increment*/ while(qptr->front != qptr->rear){ if(qptr->items[(qptr->front+1)%MAX] <small){ small = qptr->items[(qptr->front+1)%MAX]; loc = (qptr->front+1)%MAX; } qptr->front =(qptr->front+1)%MAX; }
  • 66. while(loc != qptr->rear){ qptr->items[loc] = qptr->items[(loc+1)%MAX]; (loc++)%MAX; } qptr->front=f; if(qptr->rear == 0) /*Decrement rear after removing one item*/ qptr->rear = MAX -1; else qptr->rear--; return smallest; }
  • 67. Insert Operation of Priority Queue implemented in C void insert(struct q *qptr, int item) { qptr->rear = (qptr->rear++)%MAX; /*Circular increment*/ if(qptr->rear == qptr->front){ printf("Queue overflow"); exit(1); } qptr->items[qptr->rear]=item; }
  • 68. void enqueue(pqnode front, pqnode rear, element x) { pqnode temp =(pqnode) malloc(sizeof (queue)); if (IS_FULL(temp)) { printf(“ The memory is fulln”); exit(1); } temp->data = x; temp->next= NULL; if (front) { (rear) -> next= temp;} else front = temp; rear = temp; Case Study: List-based Queue Implementation in C: insertion
  • 69. int dequeue(pqnode front) { pqnode temp = front; int x; if (IS_EMPTY(front)) { printf(“The queue is emptyn”); exit(1); } x = temp->data; front = temp->next; free(temp); return x; } Case Study: List-based Queue Implementation in C: Deletion
  • 70. Stack vs. Queue vs. Array • Stack & Queue vs. Array • Arrays are homogeneous data storage structures while stacks and queues are derived ADT data storage structures. • Stack – ADT that allows push, peep and pop. • Queue - ADT that allows enqueue and dequeue. • In an array any item can be accessed through index, while in these data structures access is restricted.
  • 71. Real world example of Queue <?xml version = "1.0"?> <!-- An author --> <author> <name gender = "male"> <first> Art </first> <last> Gentleman </last> </name> </author>