#include "iostream"
#include "string.h"
using namespace std;
struct staff
{
char num[6]; //职工工号
char name[20]; //职工姓名
double wage; //职工工资
struct staff *next;
};
struct staff *creat(int x)
{struct staff *head=NULL;
struct staff *tail,*newnode;
cout<<"请分别输入职工工号、职工姓名、职工工资"<<endl;
for(int i=0;i<x;i++)
{newnode=new staff;
cin.ignore();
gets(newnode->num);
gets(newnode->name);
cin>>newnode->wage;
if(head==NULL)
head=newnode;
else
tail->next=newnode;
tail=newnode;}
tail->next=NULL ;
return(head);}
void print(struct staff *head)
{struct staff *p=head;
while(p!=NULL)
{cout<<p->num<<" "<<p->name<<" "<<p->wage<<endl;
p=p->next;}
}
struct staff *chan(staff *head,int w,char n[])
{struct staff *p,*q;
p=head;
if(head==NULL)
cout<<"空表";
else
{while(p!=NULL&&p->num!=n)
{q=p;
p=p->next;}
p->wage=w;}
return(head);
}
int main()
{struct staff *head;
int x,w;
char n[6];
cout<<"请输入初始链表节点数x"<<endl;
cin>>x;
head=creat(x);
cout<<"请输入要修改的职工工号:"<<endl;
gets(n);
cout<<"请输入将工资改为:"<<endl;
cin>>w;
chan(head,w,n);
cout<<"修改后为:"<<endl;
print(head);
system("pause");
return 0;
}
希望有大神解答