哪位大侠帮我看看这个C++的问题出在哪里?

来源:百度知道 编辑:UC知道 时间:2024/06/06 09:35:44
原题要求从终端输入一个公司的若干人员的信息,包括员工的编号、姓名、年龄和工资总数。按照编号建立员工有序单链表输出。
#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<<'

共修改9处,请参考以下程序中的注释位置:

//---------------------------------------------------------------------------

#include <iostream>
#include <string>
using namespace std;
struct Person
{
int no;
string name;
int age;
int salary;
Person *next;
};

Person *head;

Person *insert(Person *s) /*注意这里*/
{
Person *p,*q; /*注意这里*/
/*注意这里*/
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;
return head;
}

void display(const Person *head)
{
cout<<"排序后的员工信息如下:"<<endl;
while(head)
{
cout<<head->no<<'&