Download presentation

Presentation is loading. Please wait.

Published byTrey Usrey Modified about 1 year ago

1
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Information Technology, 3’rd Semester Lecture 11: Queue

2
Outline What is Queue? What is the main Queue’s Operations? Queue implementation Queue’s application Circular Queue Emank X Mezank !!

3
What is Queue? A queue is a data structure where data enters at the rear of a list and is removed from the front of the list. Queues are an example of a first-in, first-out (FIFO) data structure. 3 Presented & Prepared by: Mahmoud R. Alfarra

4
What is Queue? We define a Queue as a list of items that are added only into the end of the list (rear) and removed from the front of list (front) 4 Presented & Prepared by: Mahmoud R. Alfarra FrontRear

5
What is the main Queue’s Operations? 5 Presented & Prepared by: Mahmoud R. Alfarra The two primary operations involving queues are adding a new item to the queue, removing an item from the queue and viewing the first item. The operation for adding a new item is called Enqueue. The operation for removing an item from a queue is called Dequeue. The Peek method is used to view the beginning item. (simply returns the item)

6
6 Presented & Prepared by: Mahmoud R. Alfarra What is the main Queue’s Operations?

7
Queue implementation 7 Presented & Prepared by: Mahmoud R. Alfarra We’ll implement the Queue as a class, called CQueue. The items of this Queue are objects of class list( car, table, …) This means that, the implementation of Queue as the linked list and differ just in the operations.

8
Queue’s application 8 Presented & Prepared by: Mahmoud R. Alfarra Queues are used to store items in the order in which they occur. Queues are used to order processes submitted to an operating system or a print spooler, and simulation applications use queues to model customers waiting in a line.

9
Queue’s application 9 Presented & Prepared by: Mahmoud R. Alfarra Information packets also wait in queues in computer networks. Each time a packet arrives at a network node, the routing node must route it to the next node on the network along the path to the packet’s final destination. The routing node routes one packet at a time, so additional packets are enqueued until the router can route them.

10
Array Implemented : Array Implemented :False-Overflow Issue First 10 Presented & Prepared by: Mahmoud R. Alfarra Suppose 50 calls to enqueue have been made, so now the queue array is full Assume 4 calls to dequeue( ) are made Assume a call to enqueue( ) is made now. The rear part seems to have no space, but the front has 4 unused spaces; if never used, they are wasted RearFront

11
Solution: A Circular Queue 11 Presented & Prepared by: Mahmoud R. Alfarra Allow the head (and the rear) to be moving targets When the rear end fills up and front part of the queue has empty slots, new insertions should go into the front end Next insertion goes into slot 0, and rear tracks it. The insertion after that goes into a lot 1, etc Frontrear 34

12
Illustration of Circular Queues 12 Presented & Prepared by: Mahmoud R. Alfarra Current state: After One Call to enqueue() rear Front rearFront Frontrear

13
Numeric for Circular Queues 13 Presented & Prepared by: Mahmoud R. Alfarra Front increases by (1 modulo size) after each dequeue( ). Front = (Front+1) % size; Rear increases by (1 modulo size) after each enqueue( ): Rear= (Rear +1) % size;

14
Emank X Mezank !! أعظم أسبـاب النجاة استعن بالله

15
Next Lecture Examples (Discovering other operations)

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google