Brief introduction of circular chain list

Source: Internet
Author: User

Circular link List is another form of the linked list, which is characterized by the pointer field of the last node in the table pointing to the head node, the entire list forming a ring. As a result, other nodes in the table can be found from any node in the table.

The structure of the circular link list is as follows:

The operation of the circular list is basically consistent with the previously written single-linked list, so I'm not going to give the detailed code anymore, and I'll say the difference between them: the difference between a circular link list and a single linked list is that the loop condition in the algorithm is not p or p-> Next is empty, and becomes whether they are equal to the head pointer.

Circular linked list is characterized by no need to increase the amount of storage, only a slight change in the way the link, you can make table processing more convenient and flexible.

We also find an example to illustrate this feature:

For example, we implement a budget that connects two linear tables (A1,a2,...,an) and (B1,B2,...,BN) to a linear table (A1,a2,...,an,b1,b2,...,bn) on a linked list.

If we do this kind of link operation on a single linked list, we all need to traverse the list A, first find the node an, the B1 link to the back of an, its complexity is O (n). But if we implement on the single loop table represented by the tail pointer, we just need to modify the pointer, without traversing, and its complexity is O (1).

The following is the list of circular links that are represented by the tail pointer

In our experiment we usually use the tail pointer to represent the loop list, because we just have to find the tail pointer, it's next is the head pointer, which is equivalent to we found the head pointer, but if we use the head pointer of the loop linked list, then if we need a tail pointer, we have to traverse the entire list.


Brief introduction of circular chain list

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.