主题:怎样编一个比较完整的查找函数
大家好,我已经编了一个查找函数,下面就是,但是作业要求是如果找不到要查找的结点,就一直向下查找直到找到,然后将其指针返回;如果找不到就要输入“对不起 没有此结点”的字样 希望大家帮忙谢了 我不太会使用if以及他的嵌套
linklist *GET (linklist *head,char ah)
{
linklist *p;
p=head;
if(p==NULL)
{
cout<<"there is not any progress"<<endl;
}
while(p!=NULL)
if(p->data!=ah)
p=p->next;
else if(p->data==ah)
cout<<"the progress has been finded"<<endl;
return p;
break;
else if(p->next==NULL)
cout<<"the letter doesn't exit"<<endl;
}
int main()
{linklist *head;
cout<<"请输入您要查找的结点:"<<endl;
char ch;
ch=getchar();
Get(head,ch);
}
linklist *GET (linklist *head,char ah)
{
linklist *p;
p=head;
if(p==NULL)
{
cout<<"there is not any progress"<<endl;
}
while(p!=NULL)
if(p->data!=ah)
p=p->next;
else if(p->data==ah)
cout<<"the progress has been finded"<<endl;
return p;
break;
else if(p->next==NULL)
cout<<"the letter doesn't exit"<<endl;
}
int main()
{linklist *head;
cout<<"请输入您要查找的结点:"<<endl;
char ch;
ch=getchar();
Get(head,ch);
}