When to use the cyclic queue and link queue

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.