我想在我的代码中使用 delete() 函数删除一个节点,但之后我在 display() 函数中进入无限循环?

I want to delete a node using the deletea() function in my code but after that i enter an infinite loop in display() function?

我多次尝试修改代码,但都没有成功

void deletea(int x)
{
int q=0,r;
while(list[q].next!=-1 && list[q].info != x)
    q = list[q].next ;
    r = list[q].next ;
    list[q].next = list[r].next ;
    list[r].next = avail ;
    avail = r;
}
void display()
{
    int p = 0;
    while(list[p].next != -1)
    {
        printf("\n%d\t%d\t%d",p,list[p].info,list[p].next) ;
        p = list[p].next ;
    }
    printf("\n%d\t%d\t%d",p,list[p].info,list[p].next) ;
}

希望用 display() 显示剩余的节点,但我进入了无限循环 --这是学校教我们的静态链表,不涉及指针

在 while 循环之后添加这个可能会有帮助

if(list[q].next == -1)
{
printf("Deletion not possible") ;
return ;
}