判断链表是否有环

int isLoop(LinkList *L)
{
LinkList *fast,*slow;
fast=slow=L;
while (fast!=NULL&&fast->next!=NULL)
{
fast=fast->next->next;
slow=slow->next;
if (fast==slow)
{
return 1;
}
}
return 0;
}

posted @ 2012-08-24 15:58  夏日冰茶  阅读(130)  评论(0)    收藏  举报