主题:请高手看看
这个是我编写的一个链表的一部分。就是在查找和修改这里出了问题/但是我不知道哪里错了呀/也有可能
是main函数里面调用错了的。请各位高手帮我看看/并且给我修改下;谢谢各位了
//链表的查找
struct lesson *find(struct lesson *head,long num)
{
struct lesson*p1,*p2;
if(head==NULL)
{
cout<<"这是一个空的课程表!"<<endl;
goto end;
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
cout<<"你找到的科目是:"<<num<<endl;
else
cout<<"没有你要找的科目"<<endl;
end:
return (head);
}
//链表的修改
struct lesson *set(struct lesson *head,long num,struct lesson *l)
{
struct lesson *p1,*p2,*p3;
p3=l;
if(head==NULL)
{
cout<<"这是一个空的课程表!"<<endl;
goto end;
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
cout<<"请输入要修改的课程的编号和名字:"<<endl;
cin>>p3->num>>p3->name;
p3->next=p1;
p2->next=p3;
}
else
cout<<"没有你想要修改的课程!"<<endl;
end:
return (head);
}
//课程的统计(没编好)
int main()
{
struct lesson *head,les;
long delnum;long fnum;long snum;
cout<<"请输入数据:"<<endl;
head=creat();//返回头指针
print(head);
cout<<"请输入要添加的科目:"<<endl;
cin>>les.num>>les.name;
head=insert(head,&les);
print(head);
cout<<"请输入要删除的科目:"<<endl;
cin>>delnum;
head=del(head,delnum);//删除后链表的头地址
print(head);
cout<<"请输入要查找的科目:"<<endl;
head=find(head,fnum);
print(head);
cout<<"请输入你要修改的科目:"<<endl;
head=set(head,snum,&les);
print(head);
return 0;
}
是main函数里面调用错了的。请各位高手帮我看看/并且给我修改下;谢谢各位了
//链表的查找
struct lesson *find(struct lesson *head,long num)
{
struct lesson*p1,*p2;
if(head==NULL)
{
cout<<"这是一个空的课程表!"<<endl;
goto end;
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
cout<<"你找到的科目是:"<<num<<endl;
else
cout<<"没有你要找的科目"<<endl;
end:
return (head);
}
//链表的修改
struct lesson *set(struct lesson *head,long num,struct lesson *l)
{
struct lesson *p1,*p2,*p3;
p3=l;
if(head==NULL)
{
cout<<"这是一个空的课程表!"<<endl;
goto end;
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
cout<<"请输入要修改的课程的编号和名字:"<<endl;
cin>>p3->num>>p3->name;
p3->next=p1;
p2->next=p3;
}
else
cout<<"没有你想要修改的课程!"<<endl;
end:
return (head);
}
//课程的统计(没编好)
int main()
{
struct lesson *head,les;
long delnum;long fnum;long snum;
cout<<"请输入数据:"<<endl;
head=creat();//返回头指针
print(head);
cout<<"请输入要添加的科目:"<<endl;
cin>>les.num>>les.name;
head=insert(head,&les);
print(head);
cout<<"请输入要删除的科目:"<<endl;
cin>>delnum;
head=del(head,delnum);//删除后链表的头地址
print(head);
cout<<"请输入要查找的科目:"<<endl;
head=find(head,fnum);
print(head);
cout<<"请输入你要修改的科目:"<<endl;
head=set(head,snum,&les);
print(head);
return 0;
}