0% found this document useful (0 votes)
19 views

Lecture 5 PDF

Uploaded by

AvanakshSingh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Lecture 5 PDF

Uploaded by

AvanakshSingh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Lecture 5

On

QUEUES

1
2
3
4
5
6
7
Algorithm: Enqueue ( ): Algorithm to add an element to queue
1. Declare array based queue and other variables:
Que[1..M], item, front, rear;
2. if (rear = 0)
{
front = rear =1;
que[rear] = item;
}
3. if (rear <M)
{
rear = rear +1;
que[rear] = item;
}

8
Else Print Over Flow Message
4. Output : Updated queue.

9
10
11
Example:-

Now we want to insert 60


The insertion of 60 returns overflow because the rear reaches the highest index value
of the array, but free spaces are available at the beginning of the queue.

12
Modified Algorithm for Enqueue ( ) Operation in Linear Queue

13
14
15
Create a Linked Based Queue

16
17
18
19
20
Example of the linear queue

21
22
23
24
25
26
27
28
29
30
31
32
33
34

You might also like