head of a Q is the next item to be removed tail of a Q is the next slot to get a new item 0 1 2 3 head = 0, size = 0, (tail = 0) // insert A A head = 0, size = 1, (tail = 1) // insert B A B head = 0, size = 2, (tail = 2) // remove an item A B head = 1, size = 1, (tail = 2) // insert C A B C head = 1, size = 2, (tail = 3) // insert D A B C D head = 1, size = 3, (tail = 0) // insert E E B C D head = 1, size = 4, (tail = 1) // remove an item E B C D head = 2, size = 3, (tail = 1) // insert F E F C D head = 2, size = 4, (tail = 2) // insert G (and trigger ArrayADT resize) 0 1 2 3 4 5 6 7 E F C D head = 2, size = 4, (tail = 2) // solution 1: move the portion that has not wrapped around E F C D C D head = 6, size = 4, (tail = 2) E F G D C D head = 6, size = 5, (tail = 3) // solution 2: move the portion that has wrapped around E F C D E F head = 2, size = 4, (tail = 6) E F C D E F G head = 2, size = 5, (tail = 7) How do we resize? Solution 2 is better because it does not need to know the new capacity. As we change array elements, the new capacity is automatically adjusted. tail = (head + size) % capacity