4.2.2.1 Queues Flashcards

1
Q

How are items added and removed from linear queues?

A

element zero of the array is the head of the queue, and to always remove the item from this location. Every time we remove the item from the head of the queue, all of the rest of the items in the queue move down by one to fill the space made by the removal of other items. We use the tail pointer to point to the next available space, rather than the last data item.
To remove we have to move the rest of the items down one. Finally we must adjust the tail pointer to reflect the change in the size of the queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the disadvantage of a linear queue?

A

It will become very slow if there are a large number of items in the queue. This is because every time the head of the queue is removed, all of the other data items in the queue will have to be moved down one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are items added and removed from circular queues?

A

Initially both head and tail point to index 0. As we add a sequence of numbers to the queue, tail is incremented to reflect this.
To remove items from the queue we remove the item indicated by head, and increment head
You do not move the remaining items along, thus saving an amount of processing time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you check for test an empty / full queue?

A

if size of queue = 0

if size of the queue reaches the maximum size of the queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly