#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
typedef struct emp
{
char ID[20];
float salary;
struct emp* next;
int code;
}Employee;
void PrintT(Employee* Head)
{
Employee* p;
p = Head;
printf("\n输出链表中员工的ID和薪资\n");
while (p)
{
printf("ID:%s\n salary:%f\n", p->ID, p->salary);
p = p->next;
}
}
Employee* CreatT(int n)
{
Employee* head, * cur, * pnew;
int i;
head = cur = NULL;
for (i = 0; i < n; i++)
{
pnew = (Employee*)malloc(sizeof(Employee));
printf("请输入第%d个员工的ID和薪资\n", i + 1);
scanf("%s%f", &pnew->ID, &pnew->salary);
if (i == 0)
{
head = cur = pnew;
}
else
{
cur->next = pnew;
cur = pnew;
}
}
cur->next = NULL;
return head;
}
Employee Delete_T(Employee Head, char* id)
{
Employee *p = Head;
p = p->next;
p->next = q->next;
free(q);
int main()
{
char ID[20];
Employee* p, * head = CreatT(5);
PrintT(head);
printf("\n请输入待删除的工号:");
scanf("%s", ID);
p = Delete_T(head, ID);
if (p) {
printf("\n待删除结果:\nID:%s\nSalary:%f\n", p->ID, p->salary);
}
else {
printf("没有删除到结果");
}
system("pause");
return 0;
}