Queues

Nathan Sprague

9/20/21

Queue Interface

Warm-up question

Queue Applications

Some Options for Circular Increment:

    
    // Option A
    index++;
    if (index == array.length) {
      index = 0;
    }
    
    // Option B
    if (index == array.length - 1) {
      index = 0;
    } else {
      index++;
    }
    
    // Option C
    index = (index + 1) % array.length;
    

Let’s take a Look at AQueue…

Dynamic-Array Based AQueue

Dynamic-Array Based AQueue

Linked Queue Socrative Question

Which of the following describes the most reasonable organization of a linked queue?

  1. enequeue and dequeue are performed at the head. There is no need to maintain a tail reference.

  2. enequeue is performed at the tail. dequeue is performed at the head.

  3. enequeue is performed at the head. dequeue is performed at the tail.

  4. Both a head and tail reference are required, but it doesn’t matter which is used for enequeue and which is used for dequeue.

Linked Queue

Linked Queue