0% found this document useful (0 votes)
42 views16 pages

Lec 7queue Final

The document discusses different types of queue data structures including simple queue, circular queue, priority queue, and deque. It describes the properties of each including FIFO for simple queues and priority-based processing for priority queues. Implementation of queues using arrays with front and rear pointers is also covered.

Uploaded by

Prince Zaid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views16 pages

Lec 7queue Final

The document discusses different types of queue data structures including simple queue, circular queue, priority queue, and deque. It describes the properties of each including FIFO for simple queues and priority-based processing for priority queues. Implementation of queues using arrays with front and rear pointers is also covered.

Uploaded by

Prince Zaid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Queue

By
Fatima Ubaid
Queue
• A queue is a linear list of elements in which deletions can take place only at one
end called the front, and insertions can take place only at the end called rear.
• Queue is a first in first out types of data structure(FIFO), the terms ‘Front’ and
‘Rear’ are used in describing a linear list only when it is implemented as a queue.
Types of Queue Data Structure
•Simple Queue
•Circular Queue
•Priority Queue
•Doubly Ended Queue
•Input Restricted Deque
•Output Restricted Deque
Circular Queue
• Types of dequeue :
• Input-restricted dequeue : In input-restricted dequeue, element can be
added at only one end but we can delete the element from both ends.
• Output-restricted dequeue : An output-restricted dequeue is a dequeue
where deletions take place at only one end but allows insertion at both
ends.
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.
• An element of higher priority is processed before any
element of lower priority
• Two element with the same priority are processed according to
the order in which they were added to the queue.
In computer science queue are used in multiple places e.g. in
time sharing system program with the same priority from a
queue waiting to be executed.
Representation of Queues

• Mostly each of our queues will be maintained by a linear array QUEUE and two
pointer variables: FRONT containing the location of the Front element of the
queue and REAR, containing the location of the rear element of the queue.
0 1 2 3 4 5 6 7
• Whenever an element is added to the queue, the value of REAR is
• increased by 1

REAR = REAR + 1
0 1 2 3 4 5 6 7
The condition FRONT = null, will indicate that the queue is empty. Whenever an
element is deleted from the queue, the value of FRONT is increased by 1

Front = Front + 1

0 1 2 3 4 5 6 7
Total Elements in Queue

• This means that after N insertion the rear element of the queue will
occupy QUEUE[N] or queue will occupy the last part of the array. This
may occur even though the queue itself may not contain many elements.

• Total number of elements in a queue


• Rear – Front + 1
Queue Creation

class Queue {

int* arr;
int qfront;
int rear;
int size;

public:
Queue() {
size = 10;
arr = new int[size];
qfront = 0;
rear = 0;
}
Insertion / Enqueue

void enqueue(int data) {


if(rear == size)
cout << "Queue is Full" << endl;
else
{
arr[rear] = data;
rear++;
}
}
Deletion / Dequeue

else
{ int ans = arr[qfront];
int dequeue() {
arr[qfront] = -1;
if(qfront == rear)
qfront++;
{
if(qfront==rear){
return -1;
qfront = 0;
Cout << “ Queue is
rear = 0;
Empty”;
}
}
return ans;
}
}
Is Empty

bool isEmpty() {
if(qfront == rear) {
return true;
}
else
{
return false;
}
}

You might also like