data structures using ‘c’ · data structures using ‘c ... queue • ordered collection of...

Post on 13-Mar-2020

12 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

DATA STRUCTURES USING ‘C’

Free Powerpoint Templates Page 2

LectureLecture--1515

Free Powerpoint Templates Page 3Free Powerpoint Templates

QUEUE

Queue

• Ordered collection of homogeneous elements

• Non-primitive linear data structure.

• A new element is added at one end calledrear end and the existing elements aredeleted from the other end called front end.

• This mechanism is called First-In-First-Out(FIFO).

• Total no of elements in queue= rear – front +1

Fig: Models of a Queue

Free Powerpoint Templates Page 6

Operations On A QueueOperations On A Queue

1.To insert an element inqueue

2.Delete an element fromqueue

Free Powerpoint Templates Page 7

The Queue OperationThe Queue Operation

Placing an item in a queue is called “insertion or enqueue”, which is done at the end of the queue called “rear”.

FrontRear

Free Powerpoint Templates Page 8

The Queue OperationThe Queue Operation

Removing an item from a queue iscalled “deletion or dequeue”, whichis done at the other end of the queue called “front”.

FrontRear

Free Powerpoint Templates Page 9

Algorithm QINSERT (ITEM)Algorithm QINSERT (ITEM)

1.If (rear = maxsize-1 )

print (“queue overflow”) and return

2.Else

rear = rear + 1

Queue [rear] = item

Free Powerpoint Templates Page 10

Algorithm QDELETE ()Algorithm QDELETE ()1.If (front =rear)

print “queue empty” and return

2. Else

Front = front + 1

item = queue [front];

Return item

Free Powerpoint Templates Page 11

Queue ApplicationsQueue Applications

Real life examplesWaiting in lineWaiting on hold for tech support

Applications related to Computer ScienceRound robin schedulingJob scheduling (FIFO Scheduling)Key board buffer

Free Powerpoint Templates Page 12

3 states of the queue3 states of the queue1.Queue is empty

FRONT=REAR2.Queue is full

REAR=N3.Queue contains element >=1

FRONT<REARNO. OF ELEMENT=REAR-FRONT+1

Free Powerpoint Templates Page 13

Representation Of QueuesRepresentation Of Queues1.Using an array2.Using linked list

Free Powerpoint Templates Page 14

top related