Skip to the content. Back to Chapter 2
<style> :not(ul) + ol { counter-reset: list-ctr; list-style-type: none; list-style-position: outside; } :not(ul) + ol > li { counter-increment: list-ctr; } :not(ul) + ol > li::before { content:"Q" counter(list-ctr) ". "; margin-left: -25px; } ol ol > li::before { content:none; } ol ul { list-style-type: lower-alpha; } ol ul ul { list-style-type: lower-roman; } ul ol { list-style-type: circle; } ol ol { list-style-type: circle; } ul { list-style-type: decimal; } ul ul { list-style-type: lower-alpha; } ul ul ul { list-style-type: lower-roman; }

Chapter 34

  1. Queue operation Queue contents Return value
    q.is_empty() [] True
    q.enqueue('Blue') ['Blue'] None
    q.enqueue('Red') ['Blue', 'Red'] None
    q.enqueue('Gren') ['Blue', 'Red', 'Green'] None
    q.is_full() ['Blue', 'Red', 'Green'] False
    q.is_empty() ['Blue', 'Red', 'Green'] False
    q.dequeue() ['Red', 'Green'] Blue
    q.enqueue('Yellow') ['Red', 'Green', 'Yellow'] None

    [√]

  2. For implementation style 1:

    1. The queue now contains ['Bob', 'Adam', 'Jack']. There are three names in the queue. There are 3 free spaces.
    2. The queue now contains ['Jason' (stale), 'Milly' (stale), 'Bob', 'Adam', 'Jack']. There are five names in the queue, two of which are stale (dequeued items that have not yet been overwritten). There is one free space. [√]
    • [None, None, None, None, None, None]
      front: 0
      rear: -1
    • ['Greg', 'Ben' (stale), 'Charlie' (stale), 'Davina', 'Enid', 'Fred']
      front: 3
      rear: 0 [√]
  3. A circular queue is an example of abstraction as it prevents the user from worrying about storing their queue in memory - the queue takes up a static size and can be treated as magic storage for the purposes of the user [√]

  4. An item joins a priority queue at the front if (and only if) it is higher priority than all other items in the queue. It joins at the rear if (and only if) it is lower priority than all other items in the queue

Exercises