为什么这个程序不对,我找不出问题
#include<iostream.h>
struct worker
{int num;
int age;
int sex;
worker *next;
};
void create (worker * &head,worker *&p,int a=0)
{worker *s;
s=new worker;
cout<<"请输入编号"<<endl;
cin>>s->num;
cout<<"请输入年龄"<<endl;
cin>>s->age;
cout<<"请输入性别。1代表男,0代表女"<<endl;
cin>>s->sex;
if(head==NULL)
head=s;
else p->next=s;
p=s;
delete s;
s=new worker;
if(a)
{p->next=NULL;
delete s;
}
return;
}
void count(worker * &head)
{worker *p; int x,y;
if(head==NULL)
{cout<<"没人"<<endl;return;
}
else p=head;
do{if(p->sex) x++;
else y++;
p=p->next;
}while(p!=NULL);
cout<<"男职工数为"<<x<<"女职工数为"<<y<<endl;
return;
}
void show (worker * &head)
{worker *p=head;
if(head==NULL)
{cout<<"没人"<<endl;return;}
else
{do{cout<<"编号"<<p->num<<endl<<"年龄"<<p->age<<endl;
if(p->sex)cout<<"性别:男"<<endl;
else cout<<"性别:女"<<endl;
p=p->next;
}while(p!=NULL);
return;
}
}
void deleteworker (worker * &head,int m)
{worker *p,*q;
if(head==NULL)
{cout<<"没人"<<endl;return;}
if(head->num==m)
{p=head;
head=head->next;
delete p;
p=NULL;
return;
}
for(q=head,p=head;p->next;q=q->next)
{if(q->next->num==m)
{p=q->next;q=p->next;delete p;
p=NULL;
return;
}
}
cout<<"没这个人"<<endl;
return;
}
void set(worker * p,worker * &head1)
{worker *q=head1;
if(head1==NULL)
{head1=p;return;
}
q->next=p;
q=q->next;
return;
}
void move(worker * &head,worker * &head1)
{worker *p,*q;
if(head==NULL)
{cout<<"没人"<<endl;return;
}
p=head;
if(head->sex==1&&head->age>60||head->sex==0&&head->age>55)
{set(head,head1);
delete p;
p=new worker;
}
else
{for(p=head;p->next;)
{if(p->next->sex==1&&p->next->age>60)
{set(p->next,head1);q=p->next;p->next=q->next;
delete q;
q=new worker;
}
else if(p->next->sex==0&&p->next->sex>55)
{set(p->next,head1);q=p->next;p->next=q->next;
delete q;
q=new worker;
}
}
}
return;
}
void main()
{int m,n;
worker *head=NULL;
worker *follow=head;
worker *head1=NULL;
do
{cout<<"请选择你想要做的事,1为输出全部职工的信息;2为统计出男女职工的人数;3为输入新职工;4为删除某个职工;5为删除60岁以上男职工和55岁以上女职工,并存在另一个地方;0为退出."<<endl;
cin>>m;
switch(m)
{case 1:{show(head);break;}
case 2:{count(head);break;}
case 3:{create(head,follow);break;}
case 4:{cout<<"请输入你想删除的人"<<endl;
cin>>n;
deleteworker(head,n);break;}
case 5:{move(head,head1);break;}
case 0:{create(head,follow,0);break;}
}
}while(m);
}