queue notes UNIT-V
queue notes UNIT-V
UNIT-III Page 1
Unit-III QUEUE Marks-20
Prof.Salunkhe A.A Sir SUB: DSU Branch: SYCO/IF (Diploma)
UNIT-III Page 2
Unit-III QUEUE Marks-20
Prof.Salunkhe A.A Sir SUB: DSU Branch: SYCO/IF (Diploma)
4.2.1 Operation on Queue (implemented by using Array)
OR ‘C’ Function for primitive operations on Queue
Q.Explain any four terms in queue?
Q.Write a procedure to insert an element into queue and to delete an element from a queue.
Q.Write the procedure for inserting an element in queue.
Q.Explain queues implementations using linked list?
Q. Enlist any four operations of queue.
Q.List the operations to be performed at front and rear and.
UNIT-III Page 3
Unit-III QUEUE Marks-20
Prof.Salunkhe A.A Sir SUB: DSU Branch: SYCO/IF (Diploma)
Rear is increased by 1 and the element x is stored at the rear end of the queue.
4) ‘C’ Function for insertion in queue.
enqueue function
Void enqueue(queue *q,int x)
{
if (qR = = -1)
{
qR= qF=0;
qdata[qR]=x;
}
else
{
qR=qR+1;
qdata[qR]=x;
}
}
Algorithm for Deletion from a queue. ‘C’ Function for Deletion from queue.
a)Deletion of the last element or only element(R=F)
1) x =data[F]
2)R=F= -1;
3)return (x);
b)Deletion of the element when the queue length >1
a) x = data[F]
b)F= F+1
c)return(x);
Q.Write a menu driven program in c languages for queue having menus:store,retrive and display
Queue.
Q.Write a C programming to implement queue with insert and delete operations.
Q.Write a menu driven program to insert and delete element in Queue and display Queue
Q.Write a program to insert element in queue.
Q.Write a code delete an element in queue.
UNIT-III Page 4
Unit-III QUEUE Marks-20
Prof.Salunkhe A.A Sir SUB: DSU Branch: SYCO/IF (Diploma)
4.3 Types of Queue
There are three types of queue
1)Linear Queue refer 4.1 Introduction of Queue
2)Circular Queue
3)Priority Queue
Fig: after insertion of the five element in array (queue) as shown in fig.
Rear=4
Queue is full
Front=0
Fig: after deletion of the two element in array (queue) as shown in fig.
Rear=4
Queue is full
Front=2
Queue is full as there is no empty space ahead of rear. we can not insert the next element
even if there is a space in front of queue.
2)Circular Queue
Q.Write suitable diagram explain the principle of circular queue.?
Q.Draw and explain circular queue in details.
Q.Define circular queue.?also explain advantages of circular queue over linear queue with example.
Q.Explain the concept of circular queue with example.
Q.What is circular queue?
Q.Describe circular queue with an example?
Q.Define circular queue.
Q.Describe circular queue .give its advantages ?
UNIT-III Page 5
Unit-III QUEUE Marks-20
Prof.Salunkhe A.A Sir SUB: DSU Branch: SYCO/IF (Diploma)
2)Circular Queue:
Circular queue is a linear data structure in which last node is connected back to first node to form
circle.
It follows FIFO Principle.
Elements are inserted at rear end and deleted from front end.
It is also known as “Ring Buffer”.
Only one pointer is required to be maintained.
If we have Array size is 5 i.e MAX is 5 then we have implementation for circular queue.
i=(i+1)% MAX
Where i will start from 0 its first index in array i.e 0
i (i+1)%MAX
0 (0+1)%5=1
1 (1+1)%5=2
2 (2+1)%5=3
UNIT-III Page 6
Unit-III QUEUE Marks-20
Prof.Salunkhe A.A Sir SUB: DSU Branch: SYCO/IF (Diploma)
3 (3+1)%5=4
4 (4+1)%5=0
When we move around an array of size five following sequence for location should be generated.
0123401234…………
Data type for Queue in circular queue or circular array ADT (Abstract Data type )
typedef struct queue
{
int data[size];
int F, R ;
} queue;
UNIT-III Page 7
Unit-III QUEUE Marks-20
Prof.Salunkhe A.A Sir SUB: DSU Branch: SYCO/IF (Diploma)
4) ‘C’ Function for insertion in queue.
enqueue function
Void enqueue(queue *q,int x)
{
if (empty(q)) /* empty queue */
{
qR=qF==0;
qdata[qR]=x;
}
else
{
qR=(qR+1)%MAX;
qdata[qR]=x;
}
}
UNIT-III Page 8
Unit-III QUEUE Marks-20
Prof.Salunkhe A.A Sir SUB: DSU Branch: SYCO/IF (Diploma)
Application :
Scheduling of job processed in computer.
Implementation of Priority queue using circular queue or circular queue ADT (Abstract
Data type )
typedef struct pqueue
{
int data[size];
int F, R ;
} pqueue;
Application of Queue
Q.State any two application of queue?
Q.Give applications of queue?
Q.State any two applications of queue?
1)Josephus Problem
2)Job Scheduling
3)Queue simulation
UNIT-III Page 9
Unit-III QUEUE Marks-20
Prof.Salunkhe A.A Sir SUB: DSU Branch: SYCO/IF (Diploma)
1)Josephus Problem
This is an interesting programming problem known as Josephus problem.
Suppose there are n student standing in queue.
student are numbered from 1 to n in clockwise direction.
We have to choose lucky Student number say m.
They start counting in clockwise direction from the student designated at 1 .
The counting proceeds until the mth student is identified .
This student is then eliminated and the process continues. after few rounds of counting only one
student is left and that student is winner.
2)Job Scheduling
Programs (Jobs) entering a computer for execution are scheduled using some strategies.
The purpose is to improve:
1)CPU utilization.
2)Response time
3)System utilization
The program(job) entering the system are stored in the queue. These jobs can be selected for
execution as per some pre-conceived strategy
Round Robin Technique:
UNIT-III Page 10