我曾多次尝试更正代码,但徒劳无功
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%dt%dt%d",p,list[p].info,list[p].next) ;
p = list[p].next ;
}
printf("n%dt%dt%d",p,list[p].info,list[p].next) ;
}
期望使用 display() 显示剩余的节点,但我进入了一个无限循环--这是在学校教给我们的链表的静态版本,不涉及指针
在 while 循环之后添加它可能会有所帮助
if(list[q].next == -1)
{
printf("Deletion not possible") ;
return ;
}