Queues Flashcards
What basis does a Queue use
A first in first out (FIFO)
4 operations of a queue
Enqueue
Dequeue
IsEmpty
IsFull
What does Enqueue do
Adds an item to the end of the queue
What does Dequeue do
Remove and return the item from the front
What does IsEmpty do
Checks if the queue is empty
What does IsFull do
Checks if the queue is full
What are the 3 types of queues
Linear
Circular
Priority
How are linear queues implemented
Can be used with a fixed array size
There will also be front and rear pointers that are the index values for the first and last item
What does the front pointer do (in a linear queue)
Next item to be removed
What does the rear pointer do (in a linear queue)
The last item added
Problem with a linear queue
Cannot add to a full queue or remove from an empty one
Need to specify the max size
How does a circular queue work
If there are spaces in the front it will reuse them if the queue is full
How can you check the number of items in a linear queue
(Rear - front) + 1
What function would you use for the pointers in a circular queue
MOD function
pointer = (pointer+1) MOD queueSize
How does a priority queue work
Some items are allowed to jump as when items are queued they will have a priority associated to them