这是第一个
#include<iostream.h>
struct worker
{
int num;
int year;
char sex;
worker *next;
}*l;
void creat(worker*&head)
{
worker *s,*p;
s=new worker;
cout<<"Please input number,year,sex of worker:\n";
cin>>s->num>>s->year>>s->sex;
while(s->num!=0)
{
if(head==NULL)head=s;
else p->next=s;
p=s;
s=new worker;
cin>>s->num>>s->year>>s->sex;
}
p->next=NULL;
delete s;
cout<<"Have built"<<endl;
}
void read(worker*head)
{
cout<<"The information of the worker:\n";
while(head)
{
cout<<head->num<<'\t'<<head->year<<'\t'<<head->sex<<endl;
head=head->next;
}
cout<<"Have read"<<endl;
}
void count(worker*&head)
{
int i=0,j=0;
while(head)
{
if(head->sex=='f')i++;
if(head->sex=='m')j++;
head=head->next;
}
cout<<"Have count"<<endl;
}
void insert(worker*&head)
{
worker*s;
while(!head->next)
{
s=new worker;
cin>>s->num>>s->year>>s->sex;
head->next=s;
delete s;
s=NULL;
}
cout<<"Have inserted"<<endl;
}
void del(worker*&head)
{
int a;
worker *k;
cout<<"Please input the number of worker you want to delete:\n";
cin>>a;
if(head->num==a)
{
k=head;
head=head->next;
delete k;
k=NULL;
cout<<"Have deleted\n";
}
for(worker*&pg=head;pg->next;pg=pg->next)
if(pg->next->num==a)
{
k=pg->next;
pg->next=k->next;
delete pg;
pg=NULL;
cout<<"Have deleted\n";
}
}
void delover(worker*&head)
{
worker *s,*x;
while(head)
{
x=head;
if((x->sex=='f'&&x->year==60)||(x->sex=='m'&&x->year==55))
{
s=new worker;
s=x;
x=x->next;
delete x;
x=NULL;
}
head=head->next;
}
cout<<"Have delete\n";
}
void main()
{
worker*haed=NULL;
creat(&head);
count(&head);
insert(&head);
del(&head);
delover(&head);
cout<<"Over"<<endl;
}
这是第二个
#include<iostream.h>
struct worker
{
int num;
int year;
char sex;
worker *next;
}*l;
void creat(worker*&head)
{
worker *s,*p;
s=new worker;
cout<<"Please input number,year,sex of worker:\n";
cin>>s->num>>s->year>>s->sex;
while(s->num!=0)
{
if(head==NULL)head=s;
else p->next=s;
p=s;
s=new worker;
cin>>s->num>>s->year>>s->sex;
}
p->next=NULL;
delete s;
cout<<"Have built"<<endl;
}
void read(worker*head)
{
cout<<"The information of the worker:\n";
while(head)
{
cout<<head->num<<'\t'<<head->year<<'\t'<<head->sex<<endl;
head=head->next;
}
cout<<"Have read"<<endl;
}
void count(worker*&head)
{
int i=0,j=0;
while(head)
{
if(head->sex=='f')i++;
if(head->sex=='m')j++;
head=head->next;
}
cout<<"Have count"<<endl;
}
void insert(worker*&head)
{
worker*s;
while(!head->next)
{
s=new worker;
cin>>s->num>>s->year>>s->sex;
head->next=s;
delete s;
s=NULL;
}
cout<<"Have inserted"<<endl;
}
void del(worker*&head)
{
int a;
worker *k;
cout<<"Please input the number of worker you want to delete:\n";
cin>>a;
if(head->num==a)
{
k=head;
head=head->next;
delete k;
k=NULL;
cout<<"Have deleted\n";
}
for(worker*&pg=head;pg->next;pg=pg->next)
if(pg->next->num==a)
{
k=pg->next;
pg->next=k->next;
delete pg;
pg=NULL;
cout<<"Have deleted\n";
}
}
void delover(worker*&head)
{
worker *s,*x;
while(head)
{
x=head;
if((x->sex=='f'&&x->year==60)||(x->sex=='m'&&x->year==55))
{
s=new worker;
s=x;
x=x->next;
delete x;
x=NULL;
}
head=head->next;
}
cout<<"Have delete\n";
}
void main()
{
worker*haed=NULL;
creat(&head);
count(&head);
insert(&head);
del(&head);
delover(&head);
cout<<"Over"<<endl;
}
这是第三个
#include<iostream.h>
struct worker
{
int num;
int year;
char sex;
worker *next;
}*l;
void creat(worker*&head)
{
worker *s,*p;
s=new worker;
cout<<"Please input number,year,sex of worker:\n";
cin>>s->num>>s->year>>s->sex;
while(s->num!=0)
{
if(head==NULL)head=s;
else p->next=s;
p=s;
s=new worker;
cin>>s->num>>s->year>>s->sex;
}
p->next=NULL;
delete s;
cout<<"Have built"<<endl;
}
void read(worker*head)
{
cout<<"The information of the worker:\n";
while(head)
{
cout<<head->num<<'\t'<<head->year<<'\t'<<head->sex<<endl;
head=head->next;
}
cout<<"Have read"<<endl;
}
void count(worker*&head)
{
int i=0,j=0;
while(head)
{
if(head->sex=='f')i++;
if(head->sex=='m')j++;
head=head->next;
}
cout<<"Have count"<<endl;
}
void insert(worker*&head)
{
worker*s;
while(!head->next)
{
s=new worker;
cin>>s->num>>s->year>>s->sex;
head->next=s;
delete s;
s=NULL;
}
cout<<"Have inserted"<<endl;
}
void del(worker*&head)
{
int a;
worker *k;
cout<<"Please input the number of worker you want to delete:\n";
cin>>a;
if(head->num==a)
{
k=head;
head=head->next;
delete k;
k=NULL;
cout<<"Have deleted\n";
}
for(worker*&pg=head;pg->next;pg=pg->next)
if(pg->next->num==a)
{
k=pg->next;
pg->next=k->next;
delete pg;
pg=NULL;
cout<<"Have deleted\n";
}
}
void delover(worker*&head)
{
worker *s,*x;
while(head)
{
x=head;
if((x->sex=='f'&&x->year==60)||(x->sex=='m'&&x->year==55))
{
s=new worker;
s=x;
x=x->next;
delete x;
x=NULL;
}
head=head->next;
}
cout<<"Have delete\n";
}
void main()
{
worker*haed=NULL;
creat(&head);
count(&head);
insert(&head);
del(&head);
delover(&head);
cout<<"Over"<<endl;
}
有劳各位好汉,小弟先拜谢了!