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。這個例子是譚浩強書上的。
1 回答

大話西游666
TA貢獻1817條經驗 獲得超14個贊
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);
}
添加回答
舉報
0/150
提交
取消