单链表查找值
#include
using namespace std;
struct node
{
int num;
node *next;
};
void set_ahead(node *head)
{
int n;
cin>>n;
while(n--)
{
node *p=new node;
cin>>p->num;
p->next=head->next;
head->next=p;
}
node *tmp=head->next;
while(n--)
{
cout<num<<' ';
tmp=tmp->next;
}
}
void found(node *head)
{
int goal;
cin>>goal;
node *pt=head->next;
while(pt)
{
if(pt->num==goal)
cout<<"Found!"<<endl;
else
pt=pt->next;
}
cout<<"Not found!"<<endl;
}
int main()
{
node *head=new node;
set_ahead(head);
found(head);
return 0;
}
为啥无法执行found函数,求帮忙看看,谢谢!