Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Click to edit Master title style

Queue and its operations


NAME :- korat Dhruv h.

D I V. : - I T- D

ENROLLMENT NO.:- 2001030108170

SUB.:- Data Structure

C E . : - C E T- 2

1
outline
Click to edit Master title style
 introduction of queue

 types of queue

 types operations on queue

 operation of isfull

 operation of isempty

 operation of enqueue

 operation of dequeue

 operation of peek

2
Introduction of queue
Click to edit Master title style
 Queue is example of linear data structure.

 Queue  follows a particular order in which the operations are


performed.

 It follows order of first in first out.

 Example of a queue is any queue of consumers for a resource


where the consumer that came first is served first.

 Queue is used in CPU scheduling, disk scheduling, networking,


operating systems etc…

 In a queue, we remove the item the least recently added.

 Queue has one side for inserting and another side for deleting.

3
Types of queue
Click to edit Master title style
There is three types of queue.
1)Simple queue
2)Circular queue
3)Double ended queue

Simple queue is queue in which insertion takes place at


the rear and removal occurs at the front. It strictly
follows the FIFO (First in First out) rule.

Circular queue is queue in which the last element


points to the first element making a circular link.

 Double ended queue is queue in which  insertion and


removal of elements can be performed from either from
the front or rear. Thus, it does not follow the FIFO (First
In First Out) rule.

4
types operations on queue
Click to edit Master title style
 There are total 5 types of operation which perform on
queue.

1.Isfull:- In this operation we check that queue is full or


not.

2.Isempty:- In this operation we check whether queue is


empty or not.

3.Enqueue:- In this operation we insert element into


queue.

4.Dequeue:- In this operation we delete element from the


queue.

5.Peek,:- In this operation we check that what  element at


the front the queue.

5
Operation of isfull
Click to edit Master title style
 In this operation we find out that our queue is full or not.

 It returns true is queue is full else it return false

 C program for isfull operation…

 int MAXSIZE = 6;
int queue[6];
int front=rear = -1;
bool isfull()
{
if(rear == MAXSIZE - 1)
return true;
else
return false;
}

6
Operation of isempty
Click to edit Master title style
 Isempty operation is used to check that queue is empty or not.

 It returns true if queue is empty else it return false.

 c program for isempty operation….

 bool isempty()
{
if(front < 0 || front > rear)
return true;
else
return false;
}

7
Operation of enqueue
Click to edit Master title style
 Enqueue operation is perform for inserting elements in
queue.

 C program for enqueue operation

 int enqueue(int data)


{
if(isfull())
return 0;
else
rear = rear + 1;
queue[rear] = data;
return 1;
}

8
Operation of dequeue
Click to edit Master title style
 Dequeue operation is perform for deleting some element from
queue.

 we can delete element which is insert first in queue.

 C program for dequeue operation…

 int dequeue()
{
if(isempty())
return 0;
else
int data = queue[front];
front = front + 1;
return data;
}

9
Operation of peek
Click to edit Master title style
 Peek operation is use to   the element at the front the queue.

 C program for peek operation…

 int peek()
{
return queue[front];
}

peek

1
0
Click to edit Master title style

THANK YOU

11

You might also like