简体   繁体   中英

Algorithm to find Length of circular double linked list

I've built a circular two-way circular list and I want to find its length. I am allowed to use the function only in the Pointer to list. In the list I have a binary field. An idea how can I do this? I have to use the binary field, I can not use the auxiliary pointer and I have to have it in good complexity.

Keep track of the element at which you start your traversal. Start walking along the list and check for each element if it is the one where you started. If it is not, you increment your count by one and continue on to the next element. If it is, you have visited every element and the current value of the count is your desired result.

您可以通过某种方式浏览列表,计算拥有多少元素,直到返回起始元素!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM