Queues Flashcards
Queues
The queue uses a first-in-first-out policy. FIFO
When you delete an item from the list, it will be the f______ item (the head), the one that has been there the longest.
When you want to insert an item into a queue, it goes to the end of the queue (the t______).
first
tail
Queues - Operations
The insert operation is called = e__________
The delete operation is called = dequeue
Both operations take O( ) time
enqueue
1 = constant time
Pointers
Queues have two pointers. The first one points to the head (Q.head) of the queue.
The second pointer(O.tail) points to the empty box after the l______ e_______ in the queue.
That is why we can only have n-1 elements in a queue.
We need a space at the end for the Q.tail pointer!
last element
Pointers Continued
When both pointers are pointing to the same element (Q.head = Q.tail), this list is e__________.
When both pointers are at pointing at the empty space at the end of the list (Q.head = Q.tail + 1)
or
The Q.head =1 and Q.tail = Q.length
the list is empty.
empty