include <malloc.h>
#define NULL 0
#define LEN sizeof(struct staff)
struct staff
{long num;
float salary;
struct staff * next;
};
int n;
struct staff *create(void)
{struct staff *head;
struct staff *p1,*p2;
n=0;
p1=p2=(struct staff *)malloc(LEN);
scanf("%ld,%lf",&p1->num,&p1->salary);
head==NULL;
while (p1->num!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct staff *)malloc(LEN);
scanf("%ld,%lf",&p1->num,&p1->salary);
}
p2->next=NULL;
return (head);
}
void list (struct staff *head)
{struct staff *p;
printf("\nNow ,these %d records are :\n",n);
p=head ;
if (head!=NULL)
do
{printf("%ld %5.1f\n",p->num,p->salary);
p=p->next;
}
while (p!=NULL);
}
struct staff *del(struct staff *head ,long num)
{struct staff *p1,*p2;
if(head==NULL){printf("\nlist null!\n");goto end;}
p1=head ;
while (num!=p1->num&&p1->next!=NULL)
{p2=p1;p1=p1->next;
}
if(num==p1->num)
{if(p1==head)head=p1->next;
else p2->next=p1->next;
printf("delete:%ld\n",num);
n=n-1;
}
else printf("%ld not been found!\n",num);
return (head);
end:NULL;}
main()
{struct staff *head ;
long del_num;
printf("input records:\n");
head =create();
list(head);
printf ("input the delete number:");
scanf("%ld",&del_num);
head =del(head,del_num);
list(head);
}
这个是我朋友给我弄的,麻烦你们看看错没错````拜托了....晚上该交作业了