#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct yg
{
char name[20];
int gz;
struct yg *next;
}s;
int size=sizeof(struct yg);
int main()
{
struct yg *list,*p1,*p2;
void printList(struct yg *list );
struct yg *del_list(struct yg *list,int salary);
char name[20];
int i,gz,n=0,salary;
list=NULL;
printf("请输入职工姓名和基本工资: \n");
scanf("%s%d",name,&gz);
while(gz!=0)
{
n++;
p1=(struct yg*)malloc(size);
strcpy(p1->name,name);p1->gz=gz;p1->next=NULL;
if(n==1)
list=p1;
else
p2->next=p1;
p2=p1;
scanf("%s%d",name,&gz);
}
printf("请输入要删除工资节点\n");
scanf("%d",&salary);
for(i=1;i<=n;i++)
list=del_list(list,salary);
printf("删除节点后的员工信息表\n");
printList(list);
return 0;
}
struct yg *del_list(struct yg *list, int salary)
{
struct yg *p1=list,*p2=list;
while((p1->gz!=salary) && (p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p1->gz==salary)
{ if(list==p1)
list=p1->next;
else
p2->next=p1->next;
free(p1);
}
return list;
}
void printList(struct yg *list ){
struct yg *p = list;
while (p != NULL){
printf("%s%6d\n", p->name,p->gz);
p = p->next;
}
printf("\n");
}
|