69,335
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <malloc.h>
#define LEN sizeof(struct worker);
struct worker *creat(void);
struct worker *del(struct worker*,long);
void print(struct worker*);
struct worker
{
long num;
char name[20];
int salary;
struct worker *next;
};
int main()
{
struct worker *head;
long del_num;
scanf("%ld",&del_num);
head=creat();
head=del(head,del_num);
print(head);
return 0;
}
struct worker *creat(void)
{
int n=0;
struct worker *p1,*p2,*head;
p1=p2=(struct worker*)malloc(LEN);
scanf("%ld",&p1->num);
scanf("%s",p1->name);
scanf("%d",&p1->salary);
if(p1->num!=0)
{
while(1)
{
n++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct worker*)malloc(LEN);
scanf("%ld",&p1->num);
scanf("%s",p1->name);
scanf("%d",&p1->salary);
}
p2->next=NULL;
}
return head;
}
struct worker *del(struct worker *head,long num)
{
struct worker *p1,*p2;
if(head == NULL)
{
printf("the list is null\n");
goto end;
}
p1=head;
while(p1->num != num&&p1->next != NULL)
{
p2=p1;
p1=p1->next;
}
if(p1->num == num)
if(p1==head) head=p1->next;
else p2->next=p1->next;
else
printf("%ld has not been found\n",num);
end:;
}
void print(struct student *head)
{
struct worker *p1;
if(head != NULL)
{
p1=head;
while(p1!=NULL)
{
printf("%ld %s %d\n",p1->num,p1->name,p1->salary);
p1=p1->next;
}
}
else
printf("the list is null\n");
}
#include <stdio.h>
#include <malloc.h>
#define LEN sizeof(struct worker)//分号去掉
struct worker *creat(void);
struct worker *del(struct worker*,long);
void print(struct worker*);
struct worker
{
long num;
char name[20];
int salary;
struct worker *next;
};
int main()
{
struct worker *head;
long del_num;
scanf("%ld",&del_num);
head=creat();
head=del(head,del_num);
print(head);
return 0;
}
struct worker *creat(void)
{
int n=0;
struct worker *p1,*p2,*head;
p1=p2=(struct worker*)malloc(LEN);
scanf("%ld",&p1->num);
scanf("%s",p1->name);
scanf("%d",&p1->salary);
if(p1->num!=0)
{
while(1)
{
n++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct worker*)malloc(LEN);
scanf("%ld",&p1->num);
scanf("%s",p1->name);
scanf("%d",&p1->salary);
}
p2->next=NULL;
}
return head;
}
struct worker *del(struct worker *head,long num)
{
struct worker *p1,*p2;
if(head == NULL)
{
printf("the list is null\n");
goto end;
}
p1=head;
while(p1->num != num&&p1->next != NULL)
{
p2=p1;
p1=p1->next;
}
if(p1->num == num)
if(p1==head) head=p1->next;
else p2->next=p1->next;
else
printf("%ld has not been found\n",num);
end:;
}
void print(struct worker *head)//这里参数错了
{
struct worker *p1;
if(head != NULL)
{
p1=head;
while(p1!=NULL)
{
printf("%ld %s %d\n",p1->num,p1->name,p1->salary);
p1=p1->next;
}
}
else
printf("the list is null\n");
}