#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct link{
int point;
char name[20];
int money;
int age;
struct link *next;
};
void Printf(struct link*head);
struct link *Insert(struct link *head);
struct link * Create();
int main(void)
{
int c;
struct link *head=NULL;
printf("人事管理系统\n");
do
{
printf("1.插入新成员\n");
printf("2.打印系统中所有成员\n");
printf("3.删除某成员\n");
printf("0.退出系统\n");
scanf("%d",&c);
if(c==1)
{
printf("输入工号 姓名 薪资 年龄\n");
head=Insert(head);
}
else if(c==2)
{
Printf(head);
}
else if(c==3)
{
}
}while(c!=0);
return 0;
}
void Printf(struct link*head)
{
struct link *p=head;
while(p)
{
printf("%d %s %d %d\n",p->point,p->name,p->money,p->age);
p=p->next;
}
}
struct link * Create()
{
struct link *head=(struct link *)malloc(sizeof(struct link *));
head->next=NULL;
return head;
}
struct link *Insert(struct link *head)
{
struct link *p=head,*mo,*h=NULL;
int fen,m,a;
char na[20];
scanf("%d %s %d %d",&fen,na,&m,&a);
if(!head)
{
head=Create();
head->money=m;
strcpy(head->name,na);
head->point=fen;
head->age=a;
}
else
{
mo=(struct link *)malloc(sizeof(struct link *));
mo->point=fen;
strcpy(mo->name,na);
mo->money=m;
mo->age=a;
while((mo->point>p->point)&&(p->next!=NULL))
{
h=p;
p=p->next;
}
if(mo->point<=p->point)
{
if(head==p)
head=mo;
else
mo->next=p;
}
else
{
p->next=mo;
mo->next=NULL;
}
}
return head;
}