Circular Linked List - Count Number of Nodes

倖福魔咒の 提交于 2021-02-11 12:33:35

问题


I am trying to find an algorithm to count the number of nodes in a Circular linked list by using one pointer only.

Does anyone know any algorithm?


回答1:


  1. Try checking this link: https://www.geeksforgeeks.org/count-nodes-circular-linked-list/

  2. We can also use array to keep count of the nodes visited and exit one's the node count becomes 2. But this approach works for linked list with unique elements only.



来源:https://stackoverflow.com/questions/55487427/circular-linked-list-count-number-of-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!