循环链接列表-节点数 [英] Circular Linked List - Count Number of Nodes

查看:58
本文介绍了循环链接列表-节点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过仅使用一个指针来找到一种算法来计算循环链表中的节点数.

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

有人知道任何算法吗?

推荐答案

  1. 尝试检查此链接: 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.

这篇关于循环链接列表-节点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆