struct Node{
int data;
Node *next;
};
Node* checkRing(Node* head,bool &ifExist){
if(head==NULL){
ifExist = false;
return NULL;
}
Node* fast = head;
Node* slow = head;
while(slow!=fast && fast!=NULL && slow!=NULL){
slow = slow->next;
fast = fast->next->next;
}
if(fast!=slow){
ifExist = false;
return NULL;
}else{
ifExist = true;
slow = head;
while(slow!=fast){
slow = slow->next;
fast = fast->next->next;
}
return slow;
}
}
判断单链表是否有环,若有请找出入口
最新推荐文章于 2024-07-23 17:45:53 发布