如何检查链表是否循环? [英] How to check the linked list is circular or not?

查看:140
本文介绍了如何检查链表是否循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人告诉我以下代码是否适用于检查

链表是否循环?

please anyone tell me whether the following code works for checking the
linked list is circular or not?

展开 | 选择 | 换行 | 行号

推荐答案

我将不得不去......不。
I''m going to have to go with... no.


找出链表是否是最好的方法循环是在一张纸上绘制你的数据结构并假装你是一台计算机。如何*你*告诉一个列表是否是循环的?


尝试绘制一个循环的假装你是一台计算机。然后绘制一个非圆形的假装你是一台电脑。


通常,如果你的最后一个元素指向你的第一个元素,那么它是圆形的。如果你想知道你是否有周期那么这是一个完全独立的问题。
The best way to figure out if a linked list is circular is to draw out your data structure on a piece of paper and pretend you are a computer. How can *you* tell if a list is circular?

Try drawing one that is circular and pretend you are a computer. Then draw one that is not circular and pretend you are a computer.

Usually if your last element points to your first element then it is circular. If you want to figure out if you have cycles then that is a complete separate issue.



请有人告诉我以下代码是否有效检查

链表是否循环?
please anyone tell me whether the following code works for checking the
linked list is circular or not?
展开 | 选择 | Wrap | 行号


这篇关于如何检查链表是否循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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