team 5

11
INTRODUCTION: INTRODUCTION: A queue is an abstract data type in which all insertions are made at one end of the list known as rear or tail of the queue. All deletions are made at the other end known as front or head of the queue. An insertion of the queue is also referred to as enqueuing. The deletion operation is referred to as dequeuing.

Upload: sathasivam-r

Post on 02-Aug-2015

21 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Team 5

INTRODUCTION:INTRODUCTION:

A queue is an abstract data type in which all insertions are made at one end of the list known as rear or tail of the queue.

All deletions are made at the other end known as front or head of the queue.

An insertion of the queue is also referred to as enqueuing.

The deletion operation is referred to as dequeuing.

Page 2: Team 5

This makes the queue a First-In-First-Out This makes the queue a First-In-First-Out (FIFO) data structure.(FIFO) data structure.

Queue overflow results from trying to add an element onto a full queue.

Queue underflow happens when trying to remove an element from an empty queue.

Page 3: Team 5

In a FIFO data structure, the first element added to the queue will be the first one to be removed.

That is once a new element is added, all elements that were added before have to be removed in order to remove the new element.

:

Page 4: Team 5

REAL-WORLD EXAMPLES:For example, in check-out lines, every time a customer finishes paying for their items that customer or the object leaves the queue from the front. This represents the “dequeue” function. Every time another object or customer enters the line to wait, they join the end of the line. This represent the “enqueue” function.The queue “size” function would return the length of the line.The “empty” function would return true only if there is no one in the line.

Page 5: Team 5

The operations that we need to implement a The operations that we need to implement a queue are: queue are:

initinitaddaddremoveremoveisFullisFullisEmptyisEmpty

Enqueue (new-item: item-type):

It adds an item onto the end of the queue.

Page 6: Team 5

front front ( item): item-type( item): item-typeIt returns the item at the front of the It returns the item at the front of the

queue.queue.

is-empty ( item):Boolean

True if no more items can be dequeued and there is no front item.

is-full (item):Boolean

True if no more items can be enqueued. get-size ( ):Integer

It returns the number of elements in the queue.

 

dequeue (new-item: item-type):It removes the item from the front of the

queue.

Page 7: Team 5

Initially head and tail position is at zero. Add 42 to queue, again we use the tail pointer to point to the next element.

Adding the further values 27, 52 and 99 to the queue.

Inserting an item into queue:

Page 8: Team 5

Removing an item from queue:The first value to remove from the queue is 42.

The remaining element is moved one position before it.

Page 9: Team 5

Pseudocode for the implementation of queue:

Insertion:

procedure insert(queue,rear,n,item){

if(rear==n)queue full

elserear=rear+1;queue[rear]=item

}

Page 10: Team 5

Deletion:

Procedure delete(queue,front,rear,item)

{

if(front==rear)

queue empty

else

item=queue[front]

front=front+1

}

Page 11: Team 5

Applications of queue in real time:1) Serving requests of a single shared

resource (printer, disk, CPU).

2) Call centre phone systems will use a queue to hold people in line until a service representative is free.

3) Buffers on MP3 players and portable CD players, iPod playlist. Playlist for mp3 players add songs to the end, play from the front of the list.