面试题一:判断链表是否带环

intFndLoop(pLinkListlist){pLinkNodefast=list->pHead;pLinkNodeslow=list->pHead;assert(list);while(fast!=NULL&&fast->next!=NULL){slow=slow->next;fast=fast->next->next;if(fast!=NULL&&slow==fast){return1;//有环}}return0;//无环}

面试题二:找到环的入口点

pLinkNodeFndLoopNode(pLinkListlist){pLinkNodefast=list->pHead;pLinkNodeslow=list->pHead;assert(list);while(fast!=NULL&&fast->next!=NULL){slow=slow->next;fast=fast->next->next;if(fast!=NULL&&slow==fast){break;}}slow=list->pHead;while(slow!=fast){slow=slow->next;fast=fast->next;}returnslow;}