vc中的end问题,和删除链表函数
在vc中好像用 goto end;不行显示error C2094: label 'end' was undefined删除链表函数中用到了
而且这个函数好像不大对,
struct student * del(struct student * head, long del_num)
{
struct student * p1, * p2;
p1 = p2 = head;
if(head == NULL)
{
printf("\n链表为空!\n");
goto end;
}
while(p1 -> num != del_num && p1 -> next != NULL);//能不能在这用else改呢????
{
p2 = p1;
p1 = p2 -> next;
}
if(p1 -> num == del_num)
{
if(head == p1) head = p1 -> next;
else
p2 -> next = p1 -> next;
n = n - 1;
printf("已删除%ld!", del_num);
}
else
printf("无法找到%d元素!", del_num);
end;
return (head);
}
{
struct student * p1, * p2;
p1 = p2 = head;
if(head == NULL)
{
printf("\n链表为空!\n");
goto end;
}
while(p1 -> num != del_num && p1 -> next != NULL);//能不能在这用else改呢????
{
p2 = p1;
p1 = p2 -> next;
}
if(p1 -> num == del_num)
{
if(head == p1) head = p1 -> next;
else
p2 -> next = p1 -> next;
n = n - 1;
printf("已删除%ld!", del_num);
}
else
printf("无法找到%d元素!", del_num);
end;
return (head);
}