判断链表是否有环
/** * 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;}
页:
[1]