从链接列表中删除循环会导致段错误

问题描述

void removeLoop(Node* head)
{
    // code here
    // just remove the loop without losing any nodes
    Node* rab=head;
    Node* tur=head;
    while(rab  && rab->next)
    {
        rab=rab->next->next;
        tur=tur->next;
        if(tur==rab)
        break;
    }
    Node* temp=NULL;
    if(rab && rab->next)
    {
        
        rab=head;
        while(rab!=tur)
        {
            rab=rab->next;
            temp=tur;
            tur=tur->next;
        }
        temp->next=NULL;
    }
}

这是我使用 floyd 算法实现的代码

问题链接 https://practice.geeksforgeeks.org/problems/remove-loop-in-linked-list/1#

提交时出现段错误,无法识别失败的特定测试用例

根据问题不需要返回任何东西。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)