1 / 20

CSC 248 – fundamentals of Data structure

CSC 248 – fundamentals of Data structure. CHAPTER 4 – QUEUE. PREPARED BY : ZANARIAH IDRUS. CHAPTER OBJECTIVES. Understanding Queue Operations on Queue Applications of Queue. APPLICATIONS OF QUEUES. Scheduler For controlling access to shared resources Maintain queues for printers’ jobs

atkinsp
Download Presentation

CSC 248 – fundamentals of Data structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 248 – fundamentals of Data structure CHAPTER 4 – QUEUE PREPARED BY : ZANARIAH IDRUS

  2. CHAPTER OBJECTIVES • Understanding Queue • Operations on Queue • Applications of Queue

  3. APPLICATIONS OF QUEUES • Scheduler • For controlling access to shared resources • Maintain queues for printers’ jobs • Maintains queues of disk input/output requests • Simulation of real world situations • Use queues to simulate waiting line queues in real scenarios • Public places such as bank, service counter and ticket counter (bus, train, flight-checki-n) • Telephone operators • Queuing system for handling calls to toll-free numbers

  4. QUEUE • Represents a waiting line. • First-in First-out (FIFO) data structure. • Nodes are removed only from the head of the queue, and are inserted only at the tail of the queue. • Insert operation is known as ENQUEUE (enQ) • Remove operation is known as DEQUEUE (deQ)

  5. ENQUEUE • Insert operation is known as ENQUEUE.

  6. DEQUEUE • Remove operation is known as DEQUEUE. • It remove an element from the front of the queue, provided the queue is not Empty

  7. OPERATIONS ON QUEUE • initializeQueue: Initializes the queue to an empty state. • isEmptyQueue: Determines whether the queue is empty. If the queue is empty, it returns the value true; otherwise, it returns the value false. • isFullQueue: Determines whether the queue is full. If the queue is full, it returns the value true; otherwise, it returns the value false. • getFront: Returns the front (first) element of the queue; the queue must exist. • back: Returns the rear (last) element of the queue; the queue must exist. • addQueue: Adds a new element to the rear of the queue; the queue must exist and must not be full. • deleteQueue: Removes the front element of the queue; the queue must exist and must not be empty.

  8. OPERATIONS ON QUEUE • Searching – search a particular element in queue (check and get the elements using dequeue method • Queue must be dequeue (remove data ) in order to traverse the queue • Removed data from queue must be keep and send into temporary queue if the data need to be used again • In queue, the order of the data will not change after and inserting process using temporary queue

  9. IMPLEMENTATION QUEUE AS ARRAY

  10. IMPLEMENTATION QUEUE AS ARRAY

  11. IMPLEMENTATION QUEUE AS LINKED LIST

  12. IMPLEMENTATION QUEUE AS LINKED LIST

  13. QUEUE CLASS DEFINITION • Class: Queue extends LinkedList class • Methods: • Constructors (default) • Enqueue (object) // insert element at the end of queue • Dequeue ( ) // remove element from front of queue • getFront ( ) // get the front element • getEnd ( ) // get the end element • isEmpty ( ) // check if queue is Empty (inherit from class LinkedList)

  14. INITIALIZE QUEUE public void initializeQueue() { for(inti = queueFront; i < queueRear; i = (i + 1) % maxQueueSize) list[i] = null; queueFront= 0; queueRear= maxQueueSize -1; count = 0; }

  15. EMPTY QUEUE & FULLQUEUE public booleanisEmptyQueue() { return (count == 0); } public booleanisFullQueue() { return (count == maxQueueSize); }

  16. FRONT public Object front() throws QueueUnderflowException { if(isEmptyQueue()) throw new QueueUnderflowException(); Object temp = list[queueFront]; return temp; }

  17. BACK public Object back() throws QueueUnderflowException { if(isEmptyQueue()) throw new QueueUnderflowException(); Object temp = list[queueRear]; return temp; }

  18. ADD QUEUE public void addQueue(Object queueElement) throws QueueOverflowException { if(isFullQueue()) throw new QueueOverflowException(); queueRear= (queueRear + 1) % maxQueueSize; //use the mod //operator to advance queueRear //because the array is circular count++; list[queueRear] = queueElement; }

  19. DELETE QUEUE public void deleteQueue() throws QueueUnderflowException { if(isEmptyQueue()) throw new QueueUnderflowException(); count--; list[queueFront] = null; queueFront = (queueFront + 1) % maxQueueSize; //use the mod //operator to advance queueFront //because the array is circular }

  20. OTHERS APPLICATIONS OF QUEUE • Simulation: technique in which one system models the behavior of another system; used when it is too expensive or dangerous to experiment with real systems. • Simulationexamples: • Wind tunnels used to experiment with design of car bodies • Flight simulators used to train airline pilots • Computer simulations: objects being usually represented as data

More Related