回复 6楼 wanglianyi1
大神,我只能改成酱紫了,能不能麻烦您帮我完善一下!!真的非常感谢!!#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct NODE
{
char name[20];
int ID;
float nianxin;
int age[3];
float high;
struct NODE *next;
} NODE;
typedef struct NODE1
{
char name[20];
char city[20];
int num;
struct NODE1 *next;
} NODE1;
int index=0;
//输入某个球员的信息
NODE *Creat(int n)
{
NODE *phead,*p,*previous;
int i;
phead=(NODE*)malloc(sizeof(NODE));
previous=phead;
previous->next=NULL;
for(i=0;i<n;i++)
{
p=(NODE*)malloc(sizeof(NODE));
printf("please input name,ID\n");
scanf("%s%d",&p->name,&p->ID);
printf("please input nianxin:\n");
scanf("%f",&p->nianxin);
printf("please input age:\n");
scanf("%d",&p->age);
printf("please input high:\n");
scanf("%f",&p->high);
previous->next=p;
p->next=NULL;
previous=p;
index++;
}
return phead;
}
//增加某个球员的信息
NODE* Insert(NODE *phead)
{
NODE *ptemp,*p1;
ptemp=phead;
p1=(NODE*)malloc(sizeof(NODE));
printf("please input name,ID\n");
scanf("%s%d",&p1->name,&p1->ID);
printf("please input nianxin:\n");
scanf("%f",&p1->nianxin);
printf("please input age:\n");
scanf("%d",&p1->age);
printf("please input high:\n");
scanf("%f",&p1->high);
p1->next=ptemp->next;
ptemp->next=p1;
index++;
return phead;
}
//删除某个球员的信息
NODE* Delete(NODE*phead ,int i)
{
NODE *ptemp,*previous;
ptemp=phead;
ptemp=ptemp->next;
previous=ptemp;
while(ptemp!=NULL&&(ptemp->ID!=i))
{
previous=ptemp;
ptemp=ptemp->next;
}
if(ptemp)
{
previous->next=ptemp->next;
free(ptemp);
printf("删除成功!\n");
}
return phead;
}
//查找某个球员的信息
void Lookfor(NODE *phead,int i)
{
NODE *ptemp;
ptemp=phead;
ptemp=ptemp->next;
while(ptemp!=NULL&&(ptemp->ID!=i))
ptemp=ptemp->next;
if(ptemp)
{
printf("*********球员信息************\n");
printf("编号: %d\t姓名: %s\n",ptemp->ID,ptemp->name);
printf("年薪: %f\n",ptemp->nianxin);
printf("年龄: %d\n",ptemp->age);
printf("身高: %f\n",ptemp->nianxin);
}
}
//增加球队
NODE1* insert(NODE1 *phead)
{
NODE1 *ptemp,*p1;
ptemp=phead;
p1=(NODE1*)malloc(sizeof(NODE1));
printf("please input name\n");
scanf("%s",&p1->name);
printf("please input city:\n");
scanf("%s",&p1->city);
printf("please input num:\n");
scanf("%d",&p1->num);
p1->next=ptemp->next;
ptemp->next=p1;
index++;
return phead;
}
//删除球队
NODE1* delete(NODE1*phead ,char name[20])
{
NODE1 *ptemp,*previous;
ptemp=phead;
ptemp=ptemp->next;
previous=ptemp;
while(ptemp!=NULL&&(ptemp->name!=name))
{
previous=ptemp;
ptemp=ptemp->next;
}
if(ptemp)
{
previous->next=ptemp->next;
free(ptemp);
printf("删除成功!\n");
}
return phead;
}
//修改球员的信息
void Revise_information(NODE*phead,int i)
{
NODE *ptemp;
ptemp=phead;
ptemp=ptemp->next;
while(ptemp!=NULL&&(ptemp->ID!=i))
{
ptemp=ptemp->next;
}
if(ptemp)
{
printf("请输入修改的姓名:");
scanf("%s",&ptemp->name);
printf("请输入要修改的编号:");
scanf("%d",&ptemp->ID);
printf("请输入要修改的年薪:");
scanf("%f",&ptemp->nianxin);
printf("请输入要修改的年龄:");
scanf("%f",&ptemp->age);
printf("请输入要修改的身高:");
scanf("%f",&ptemp->high);
printf("修改成功!\n");
}
}
//按照年薪递增的顺序排列
NODE* Ascendline(NODE*phead)
{
NODE*ptemp,*previous,*p1;
int i;
for(i=0;i<index;i++)
{
ptemp=phead;
p1=ptemp;
previous=ptemp=ptemp->next;
ptemp=ptemp->next;
while(ptemp!=NULL)
{
float m,n;
m=ptemp->nianxin;
n=previous->nianxin;
if(n>m)
{
p1->next=ptemp;
previous->next=ptemp->next;
ptemp->next=previous;
}
p1=previous;
previous=ptemp;
ptemp=ptemp->next;
}
}
return phead;
}
//按照递减的顺序排列
void menu()
{
printf("*************NBA球队信息查询系统************************\n");
printf("1.输入球员的信息\n");
printf("2.\n");
printf("3.增加某个球员的信息\n");
printf("4.删除某个球员的信息\n");
printf("5.查找某个球员的信息\n");
printf("6.增加球队\n");
printf("7.删除球队\n");
printf("8.修改球员的信息\n");
printf("9.按照年薪递增的顺序排列\n");
printf("10.\n");
}#include "head.h"
void main()
{
int n,i;
NODE *phead;
menu();
scanf("%d",&n);
while(n)
{
switch(n)
{
case 1:printf("请问要输入几个球员的信息:\n");
scanf("%d",&i);
phead=Creat(i);
break;
case 2:;
break;
case 3:phead=Insert(phead);
break;
case 4:printf("请输入要删除球员的编号:");
scanf("%d",&i);
Delete(phead,i);
break;
case 5:printf("请输入要查找球员的编号:");
scanf("%d",&i);
Lookfor(phead,i);
break;
case 6:phead=insert(phead);
break;
case 7:printf("请输入要删除球队的名称:");
scanf("%s",name);
delete(phead,name);
break;
case 8:printf("请输入要修改球员的编号:\n");
scanf("%d",&i);
Revise_information(phead,i);break;
case 9:phead=Ascendline(phead);printf("排序完成!\n");
Print(phead);
break;
case 10:;
break;
default:printf("输入错误!\n");break;
}
menu();
scanf("%d",&n);
}
}