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

6.implementation of Queue in C++

This document discusses queues as a data structure. It defines queues as FIFO structures that add elements to one end (rear) and remove from the other (front). The key operations are enqueue to add to the rear and dequeue to remove from the front. Queues can overflow if adding to a full queue or underflow if removing from an empty queue. Implementation of queues in a program is also mentioned.

Uploaded by

Muhammad Ali
Copyright
© © All Rights Reserved
0% found this document useful (0 votes)
33 views

6.implementation of Queue in C++

This document discusses queues as a data structure. It defines queues as FIFO structures that add elements to one end (rear) and remove from the other (front). The key operations are enqueue to add to the rear and dequeue to remove from the front. Queues can overflow if adding to a full queue or underflow if removing from an empty queue. Implementation of queues in a program is also mentioned.

Uploaded by

Muhammad Ali
Copyright
© © All Rights Reserved
You are on page 1/ 11

Course: Data Structure and Algorithms Lab

Instructor: Engr. Syed Abuzar Bacha

Department of Electrical Engineering, UET MARDAN


What is a queue?
 a FIFO (first in, first out) data structure.
 Queues have two ends:
 Elements are added at one end.
 Elements are removed from the other end.
 The element added first is also removed first
(FIFO: First In, First Out).
Queue Locations and Operations

 Rear: Position where elements are added


 Front: Position from which elements are
removed
 Enqueue: Add an element to the rear of the
queue
 Dequeue: Remove an element from the
front of a queue

18-3
The Queue As an ADT
 In the sequence
 Items can be removed only at the front
 Items can be added only at the other end, the back

4
The Queue Operations

 New item must enter the queue at the


rear. It is usually called an enqueue
operation.

$ $

Front
Rear
The Queue Operations

 When an item is taken from the


queue, it always comes from the
front. It is usually called a dequeue
operation.
$ $

Front
Rear
Queue overflow
 The condition resulting from trying to add
an element onto a full queue.
Queue underflow

 The condition resulting from trying to


remove an element from an empty queue.
Implementation of Queue
Implementation of Queue
Implementation of Queue

You might also like