且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查链表是否循环?

更新时间:2022-12-13 21:29:10

我将不得不去......不。
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 | 行号