C#判断单链表是否有环
摘要:
static bool IfCircle(SingleLinkNode node) { SingleLinkNode slowNode = node, fastNode = node; while(node.NextNode != null) { slowNode = slowNode.NextNode; //相当于步长为1的节点指针 fastNode = fastNode.NextNode; //相当于步长为2的节点指针 if (fastNode.NextNode!= null) fastNode = fastNode.NextNode; else return false; node =. 阅读全文
posted @ 2010-01-27 20:32 MikeJia 阅读(779) 评论(0) 推荐(0) 编辑