#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
char name[20];
int salary;
struct empNode *next;
}empNode;
int size = sizeof(empNode);
empNode *delList(empNode *list);
void main()
{
empNode *list, *p = NULL, *q = NULL;
char name[20];
int num = 0, add = 0, salary, n = 0;
list = NULL;
printf("请输入姓名和工资(工资输入0,结束输入):\n");
scanf("%s%d", name, &salary);
while (salary != 0)
{
n++;
p = (struct empNode*)malloc(size);
strcpy(p->name, name);
p->salary = salary;
p->next = NULL;
if (n == 1)list = p;
else q->next = p;
q = p;
scanf("%s%d", name, &salary);
}
list=delList(list);
p = list;
printf("删除后的链表信息为:\n");
while (p != NULL)
{
printf("%s %d\n", p->name, p->salary);
p = p->next;
}
}
empNode *delList(empNode *list)
{
int delsalary;
printf("请输入要删除的工资:");
scanf("%d", &delsalary);
empNode *p = list, *del = NULL;
while (p != NULL)
{
if (list->salary == delsalary)
{
list = list->next;
p = list;
}
else if (p->next == delsalary)
{
del = p->next;
p->next = del->next;
free(del);
}
p = p->next;
}
return list;
}
为什么结果还是原来的链表?