Queues are first-in, first-out (FIFO) data structures. Items are added to the rear of the queue and removed from the front. Common queue operations include enqueue to add an item, dequeue to remove an item, and isEmpty to check if the queue is empty. Queues can be implemented using linked lists or arrays. Array implementations require additional logic to handle wrapping around when the front or back reaches the end. Queues are useful for sharing resources like printers where requests are processed in the order received. Priority queues prioritize items, allowing higher priority items to be placed at the front of the queue ahead of lower priority items.
Queues are first-in, first-out (FIFO) data structures. Items are added to the rear of the queue and removed from the front. Common queue operations include enqueue to add an item, dequeue to remove an item, and isEmpty to check if the queue is empty. Queues can be implemented using linked lists or arrays. Array implementations require additional logic to handle wrapping around when the front or back reaches the end. Queues are useful for sharing resources like printers where requests are processed in the order received. Priority queues prioritize items, allowing higher priority items to be placed at the front of the queue ahead of lower priority items.
Queues are first-in, first-out (FIFO) data structures. Items are added to the rear of the queue and removed from the front. Common queue operations include enqueue to add an item, dequeue to remove an item, and isEmpty to check if the queue is empty. Queues can be implemented using linked lists or arrays. Array implementations require additional logic to handle wrapping around when the front or back reaches the end. Queues are useful for sharing resources like printers where requests are processed in the order received. Priority queues prioritize items, allowing higher priority items to be placed at the front of the queue ahead of lower priority items.
As the name implies: a first-in,first-out(FIFO) list
Items can only be inserted at the backend deleted from the front QUEUES - BASIC OPERATIONS enqueue(el): put the element el at the end of the list. dequeue(): returns the first element in the queue.
isEmpty(): checks if the queue is empty
QUEUES - IMPLEMENTATION
Linked List Implementation
enqueue: We insert elements at the tail dequeue: We delete elements from the head QUEUES - IMPLEMENTATION(2) Array Implementation We save the “front” and “back” of the queue in the array.
enqueue(item): we increment “back” and set
array[back]=item dequeue(): we return array[front] and increment “front” QUEUES - IMPLEMENTATION(3) Array Implementation Drawback After several elements have been enqueued and dequeued, the queue may appear to be full, since “back” is now at the last array index However, there might only be a few elements in the queue. QUEUES - IMPLEMENTATION(4) “Circular” Array Implementation Whenever front or back gets to the end of the array, it is wrapped around to the beginning.
This requires a little extra code.
QUEUES - APPLICATIONS
In software application where a single resource has to be
shared Printers, Storage Devices ...Example: if multiple programs send print jobs to the printer one after the other, their request is queued since the printer cannot server the requests all at once. Using queueing theory to model and simulate Customer service in banks and other places where there are queues. Traffic in communication networks PRIORITY QUEUE
• Much like an ordinary
queue • Items are removed from the front • But, Items are NOT added at the back higher priority items are inserted at the front