单链表是通过指针调用的,你要是用的话我给你一个
#include<stdio.h>
#include<stdlib.h>
struct node
{
int id;
char name[10];
float english,math,computer,zongfen,pingjunfen;
struct node *next;
}*head;
void luru();
void shanchu();
void xiugai();
void xianshi();
void zongfenhepingjunfen();
void luru()
{
float a;
struct node *p,*q;
if(head==NULL)
{
head=(struct node *) malloc(sizeof(struct node));
head->next=NULL;
}
p=(struct node *) malloc(sizeof(struct node));
printf(" qingshuruxuehao:");
scanf("%d",&p->id);
printf(" qingshuruxingming:");
scanf("%s",&p->name);
for(;;)
{
printf(" qingshuruyingyu(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shuruyingyuyouwu!\n");
continue;
}
else break;
}
p->english=a;
for(;;)
{
printf(" qingshurushuxue(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shurushuxueyouwu!\n");
continue;
}
else break;
}
p->math=a;
for(;;)
{
printf(" qingshurujisuanji(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shurujisuanjiyouwu!\n");
continue;
}
else break;
}
p->computer=a;
p->next=NULL;
q=head;
if(head->next==NULL)
{
head->next=p;
}
else
{
while(q->next!=NULL)
q=q->next;q->next=p;
}
}
void shanchu(n)
{
struct node *q1,*q2,*q3;
q1=head;
q3=q1;
if(head->next==NULL)
{
printf(" chengjibiaowujilu!\n");
}
else
{
while(q1->id!=n && q1->next!=NULL)
{
q3=q1;q1=q1->next;
}
if(q1->id==n)
{
q2=q3->next;
q3->next=q2->next;
free(q2);
}
else return;
}
}
void xiugai()
{
int n;
struct node *p;
float a;
p=(struct node *) malloc(sizeof(struct node));
p->next=NULL;
printf(" qingshuruyaoxiugaidexuehao:");
scanf("%d",&n);
p->id=n;
p=head;
if(p!=NULL)
{
while(p->id!=n && p->next!=NULL)
{
p=p->next;
}
if(p->id==n)
{
printf(" qingshuruxingming:");
scanf("%s",&p->name);
for(;;)
{
printf(" qingshuruyingyu(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shuruyingyuyouwu!\n");
continue;
}
else break;
}
p->english=a;
for(;;)
{
printf(" qingshurushuxue(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shuruyingyuyouwu!\n");
continue;
}
else break;
}
p->math=a;
for(;;)
{
printf(" qingshurujisuanji(0~100):");
scanf("%f",&a);
if(a<0||a>100)
{
printf(" shuruyingyuyouwu!\n");
continue;
}
else break;
}
p->computer=a;
}
else
printf(" xuehaobucunzai!\n");
}
else
printf(" xuehaobucunzai!\n");
}
void xianshi()
{
struct node *p;
p=head;
if(p->next==NULL)
{
printf(" chengjibiaowujilu!\n");
}
else
{
printf(" xuehao xingming yingyu shuxue jisuanji\n");
while(p->next!=NULL)
{
printf(" %d %s %3.2f %3.2f %3.2f\n",p->next->id,p->next->name,p->next->english,p->next->math,p->next->computer);
p=p->next;
}
}
}
void zongfenhepingjunfen()
{
struct node *p;
p=head;
p->zongfen=p->english+p->math+p->computer;
p->pingjunfen=p->zongfen/3;
p=head;
if(p->next==NULL)
{
printf(" chengjibiaowujilu!\n");
}
else
{
printf(" xuehao xingming zongfen pingjunfen\n");
while(p->next!=NULL)
{
printf(" %d %s %3.2f %3.2f\n",p->next->id,p->next->name,p->next->zongfen,p->next->pingjunfen);
p=p->next;
}
}
}
main()
{
int x,n;
for(;;)
{
printf(" chengjiguanli \n");
printf(" ----------------------------------------\n");
printf(" | 1.chengjiluru |\n");
printf(" | 2.chengjishanchu |\n");
printf(" | 3.chengjixiugai |\n");
printf(" | 4.chengjixianshi |\n");
printf(" | 5.jisuanzongfenhepingjunfen |\n");
printf(" | 0.tuichu! |\n");
printf(" ----------------------------------------\n");
printf(" qingshurugongnenghao:");
scanf("%d",&x);
if(x==1) luru();
if(x==2)
{
printf(" qingshuruyaoshanchudexuehao:");
scanf("%d",&n);
shanchu(n);
}
if(x==3) xiugai();
if(x==4) xianshi();
if(x==5) zongfenhepingjunfen();
if(x==0) break;
}
}
对了,上面的没有成绩查找,补充一下:
这是一个自定义的一个函数:只要加在里面就可以了,记得要在前面定义一 下,命令是void chazhao();
void chazhao()
{
int n;
struct node *p;
float a;
p=(struct node *) malloc(sizeof(struct node));
p->next=NULL;
printf(" qingshuruyaochazhaodexuehao:");
scanf("%d",&n);
p->id=n;
p=head;
if(p!=NULL)
{
while(p->id!=n && p->next!=NULL)
{
p=p->next;
}
if(p->id==n)
{
printf(" xuehao xingming yingyu shuxue jisuanji\n");
printf(" %d %s %3.2f %3.2f %3.2f\n",p->id,p->name,p->english,p->math,p->computer);
}
}
}
最后在主函数里面输入一条显示成绩查找的命令就可以了,命令是printf(" | 3.chengjichazhao |\n");
在主函数里面直接调用函数chazhao();
这样就可以了!