您的位置:首页 > 职场人生

从1.5K到18K 一个程序员的5年成长之路(三)

2013-05-22 08:22 141 查看
/**
* if has loop return 1 else return 0
*/
static int has_loop(List *list)
{
List *pFast;
List *pSlow;

pFast = pSlow = list;

if (pFast != NULL && pFast->next != NULL) {
pFast = pFast->next->next;
} else {
return 0;
}

while (pFast != pSlow) {
if (pFast != NULL && pFast->next != NULL)
pFast = pFast->next->next;
else
break;
pSlow = pSlow->next;
}

if (pFast == pSlow)
return 1;
else
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: