谁能帮我看看这个c++程序的问题(关于单链表)
原题要求从终端输入一个公司的若干人员的信息,包括员工的编号、姓名、年龄和工资总数。按照编号建立员工有序单链表输出。#include <iostream>
#include <string>
using namespace std;
struct Person
{
int no;
string name;
int age;
int salary;
Person *next;
};
Person *head;
Person *insert(Person *f)
{
Person *s,*p,*q;
s=new Person;
s=f;
s->next=NULL;
if(head==NULL)
{
head=s;
return head;
}
if(head->no>s->no)
{
s->next=head,head=s;
return head;
}
for(q=head,p=head->next;p;q=p,p=p->next)
if(p->no>s->no)
{
s->next=p;
q->next=s;
return head;
}
q->next=s;//p是否也行?
return head;
}
void display(const Person *head)//不用const是否可以?
{
cout<<"排序后的员工信息如下:"<<endl;
while(head)
{
cout<<head->no<<'\t'<<head->name<<'\t'<<head->age<<'\t'<<head->salary<<endl;
head=head->next;
}
}
main()
{
Person *staff=new Person;
head=NULL;
cin>>staff->no>>staff->name>>staff->age>>staff->salary;
while(staff->no!=0)
{
head=insert(staff);//漏了head=
cin>>staff->no>>staff->name>>staff->age>>staff->salary;
}
display(head);
return 0;
}
请问错在哪里,应该怎么改??