关于链表的一道题
#include<iostream> using namespace std;
int m,n;
struct node
{ int num;
char name[10];
int age;
int salary;
}a;
struct list
{ node data;
list *next;
};
list *head;
list *input(node)
{ list *s,*p,*q;
s=new list;
s->data=a;s->next=NULL;
if (head==NULL)
{head=s;return head;}
if (head->data.num>s->data.num)
{s->next=head;head=s;
return (head);
}
for(q=head,p=head->next;p;q=p,p=p->next)
if (p->data.num>s->data.num)
{s->next=p;q->next=s;
return ( head ) ;
}
q->next=s;
return (head);
}
void showlist(const list *)
{cout<<"Now the sorted information are:\n";
while(head)
{cout<<head->data.num<<head->data.name<<head->data.age<<head->data.salary<<endl;head=head->next;}
return;
}
void find_people(const list *head)
{ list *h=new list;
cin>>h->data.num;
int flag=0;
{while(head)
if(head->data.num==h->data.num) {cout<<head->data.num<<" "<<head->data.name<<" "<<head->data.age<<" "<<head->data.salary<<endl;return;}
head=head->next;
}
cout<<"can't find!"<<endl;
return;
}
void main()
{ cout<<"Input the total:";
cin>>m;
head=NULL;
cout<<"Input the information of the "<<m<<" students."<<endl;
cin>>a.num>>a.name>>a.age>>a.salary;
head=NULL;
while(a.num!=0)
{head=input(a);cin>>a.num>>a.name>>a.age>>a.salary;}
showlist(head);
cout<<"Please input the num of the person you want:\n";
find_people(head);
}
这道题要求输入若干员工信息,按照编号由小到大遍历输出
输入一个编号输出指定员工的信息
是不是在定义void find_people(const list *head) 时出错了?