goto end;可以用什么函数替换

来源:百度知道 编辑:UC知道 时间:2024/05/12 05:08:55
struct student *del(struct student *head,long num)
{
struct student *p1,*p2;
if(head==NULL)
{
printf("\n空链表\n");
goto end;
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)
head=p1->next;
else p2->next=p1->next;
printf("删除:%ld\n",num);
n=n-1;
}
else printf("%ld 没有找到!",num);
end;
return(head);
}
我用的dev c++,没有end。
这个例子是谭浩强书上的。

struct student *del(struct student *head,long num)
{
struct student *p1,*p2;
int flag = 1;
if(head==NULL)
{
printf("\n空链表\n");
flag = 0;
}
if(flag)
{
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)
head=p1->next;
else p2->next=p1->next;
printf("删除:%ld\n",num);
n=n-1;
}
else printf("%ld 没有找到!",num);
}
return(head);
}