For the comparison between the circular queue and the chain queue, you can consider two aspects: New York entertainment city
- In terms of time, in fact, their basic operations are constant time, that is, they are all 0 (1), but the cyclic queue applies for a good space in advance and will not be released during use, but for the chain queue, there will also be some time overhead for each application and release node. If the teams are frequent, there is still a slight difference between the two.
- In terms of space, the cyclic queue must have a fixed length, so there is a problem of the number of storage elements and the waste of space. This problem does not exist in the chain queue. Although it requires a pointer field, it will produce some space overhead, but it is acceptable. Therefore, in space, the chain queue is more flexible.
- In general, we recommend that you use a cyclic queue when you can determine the maximum length of the queue. If you cannot predict the length of the queue, use a chain queue.
When an array is used to implement a queue, if the queue is not moved, a false full queue may occur as the data continues to be read and written. That is, the group of tails is full, but the header array is still empty. Cyclic queue is also an array, but it logically connects the array header and the end to form a cyclic queue. when the end of the array is full, you must determine whether the array header is empty, it is not empty and continues to store data, which can effectively use resources. However, it is difficult to determine whether the number of columns is empty or full when using cyclic queues;
The above problem does not exist in the chain queue. The biggest advantage of "cyclic queue" is space saving and less space allocation, while the link queue has a little more address storage overhead.
When to use the cyclic queue and link queue