Presentation is loading. Please wait.

Presentation is loading. Please wait.

Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.

Similar presentations


Presentation on theme: "Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made."— Presentation transcript:

1 Give Eg:? Queues

2 Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made at the other end. Insertion are made ->Rear end Deletion are made ->Front end Referred as FIFO Eg: Representation of queue 1) -> Front end pointer points –first element. ->Rear end pointer points – Last element. Queues

3 Do you like to wait in line ? Neither do I. Next time you are stuck waiting in line, observe the obvious: People enter the line at the back. People exit the line from the front. Is there anyone on line? How many people are on line?

4 Implementation of Queue Eg: For queue with max=6,Element filled is 5. Then point out front and rear pointer. Then delete 3 element and show the two pointers pointing. And a new element and show the two pointers.

5 Primary operation on queue. ? This operation referred as enqueue(insertion),dequeue(deletion).  Enqueue add new element.  Dequeue ?  This process is carried out by incrementing the rear end for adding.  Decrementing the front end for deleting. enqueue - add a new item at the back of the queue dequeue - remove the item at the front of the queue isEmpty - check if the queue is empty size - count the number of items on the queue

6 Types of Queues  Linear queues  Circular queues  Dequeues  Priority queues

7 Linear queues The queue that we have seen so far. Queue has _______ ends. Rear end used for ______. Front end used for ______. Traversing takes place only one direction ( ie front to rear). Eg Picture:

8 Circular queues

9 Implementation of Queue Eg: For queue with max=6,Element filled is 5. Then point out front and rear pointer. Then delete 3 element and show the two pointers pointing. And a new element and show the two pointers.

10 Dequeue Double ended queue is another form of a queue in which insertions and deletions are made at both(i.e front and rear ends) Eg: Two variations: 1.Input restricted queue(i.e Insertion at one end either front or rear). 2.Output restricted queue(i.e deletion at one end either front or rear). Pic.eg:

11 Different types of dequeues 1)Linear dequeue 2)Circular dequeue. 1)Linear dequeue Similar to a linear queue except the following conditions, ->The insertions and deletions are made at both the front and rear ends of the dequeue. ->If the front end is in the first position,u cannot insert the data at front end. ->If the rear end is in the last position,u cannot insert the data at rear end. Eg:

12 Representation of Dequeue

13 Circular dequeue Similar to a circular queue except the following conditions: ->The insertions and deletions are made at both the front and rear ends of the dequeue. ->Irrespective of the positions of the front and rear end, u can insert and delete data. Eg: After deletion at rear end eg with pic… After insertion at front end eg with pic… After insertion at rear end eg with pic… After deletion of front end eg with pic…

14 Priority queue -> Element is assigned a priority and the elements are added or removed according to that priority. Rules: -Element with high priority is processed before any element of lower priority. -The elements with the same priority are processed according to the order in which they were added to the queue.

15 Priority queue with multiple queue

16 Priority queue as a two-dimensional array

17 Linked list implementation of queue Enqueue operation is performed at the end. Dequeue operation is performed at the front. Eg: for empty queue,enqueue,dequeue operation.


Download ppt "Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made."

Similar presentations


Ads by Google