主题:帮忙!高手!我程序出了问题!请解决一下!
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct geshou{
float score[9];
float average;
struct geshou *next;
char name[100];
}gs;
gs *createfirst()
{
gs *s,*h;
int n,i,j;
float sum;
int a,b;
float temp;
h=(gs*)malloc(sizeof(gs));
h->next=NULL;
printf("请输入参加比赛的歌手人数:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
s=(gs*)malloc(sizeof(gs));
printf("请输入参加比赛第%d号歌手姓名:",i);
scanf("%s",s->name);
printf("请输入参加比赛第%d号歌手分数:",i);
for(sum=0,j=0;j<=8;j++)
{
scanf("%f",&(s->score[j]));
sum+=(s->score[j]);
}
a=0;
b=1;
while((a<9)&&(b>0))
{
b=0;
for(j=8;j>a;j--)
{
if(s->score[j]<s->score[j-1])
{temp=s->score[j];
s->score[j]=s->score[j-1];
s->score[j-1]=temp;
b++;
}
}
a++;
}
sum=sum-(s->score[0])-(s->score[8]);
s->average=sum/9.0;
s->next=h->next;
h->next=s;
}
return h;
}
void insertlist(gs *h)
{
gs *s1;
int a1,b1,j1;
float temp1,sum1;
s1=(gs*)malloc(sizeof(gs));
printf("请输入添加的比赛的歌手姓名:");
scanf("%s",s1->name);
printf("请输入添加的比赛的歌手的9个分数:");
for(sum1=0,j1=0;j1<=8;j1++)
{
scanf("%f",&(s1->score[j1]));
sum1+=(s1->score[j1]);
}
a1=0;
b1=1;
while((a1<9)&&(b1>0))
{
b1=0;
for(j1=8;j1>a1;j1--)
{
if(s1->score[j1]<s1->score[j1-1])
{temp1=s1->score[j1];
s1->score[j1]=s1->score[j1-1];
s1->score[j1-1]=temp1;
b1++;
}
}
a1++;
}
sum1=sum1-(s1->score[0])-(s1->score[8]);
s1->average=sum1/9.0;
s1->next=h->next;
h->next=s1;
}
void deletelist(gs *h)
{
gs *p3,*p4;
p3=h;
while(p3->next!=NULL)
{
if(p3->next->name=="jh")
{
p4=p3->next;
p3->next=p4->next;
free(p4);
}
else
p3=p3->next;
}
}
void paixu(gs *h)
{
gs *P,*Q,*P1,*Q1;
P=Q=Q1=h;
P1=P->next;
if(P1->average<P->average)
{ P=P1;
Q=Q1;}
Q1=P1;
P1=P1->next;
}
void display(gs *h)
{
gs *q;
int m;
q=h->next;
while(q!=NULL)
{
printf("%s\n",q->name);
printf("%.1f\n",q->average);
q=q->next;
}
}
void main()
{
gs *p;
p=createfirst();
deletelist(p);
display(p);
}
请您帮我看一下为什麽我用链表编的这个程序中deletelist(gs *h)和 paixu(gs *h)函数用不了,谢谢
急用!!!!请星期日回复
#include<stdio.h>
#include<math.h>
typedef struct geshou{
float score[9];
float average;
struct geshou *next;
char name[100];
}gs;
gs *createfirst()
{
gs *s,*h;
int n,i,j;
float sum;
int a,b;
float temp;
h=(gs*)malloc(sizeof(gs));
h->next=NULL;
printf("请输入参加比赛的歌手人数:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
s=(gs*)malloc(sizeof(gs));
printf("请输入参加比赛第%d号歌手姓名:",i);
scanf("%s",s->name);
printf("请输入参加比赛第%d号歌手分数:",i);
for(sum=0,j=0;j<=8;j++)
{
scanf("%f",&(s->score[j]));
sum+=(s->score[j]);
}
a=0;
b=1;
while((a<9)&&(b>0))
{
b=0;
for(j=8;j>a;j--)
{
if(s->score[j]<s->score[j-1])
{temp=s->score[j];
s->score[j]=s->score[j-1];
s->score[j-1]=temp;
b++;
}
}
a++;
}
sum=sum-(s->score[0])-(s->score[8]);
s->average=sum/9.0;
s->next=h->next;
h->next=s;
}
return h;
}
void insertlist(gs *h)
{
gs *s1;
int a1,b1,j1;
float temp1,sum1;
s1=(gs*)malloc(sizeof(gs));
printf("请输入添加的比赛的歌手姓名:");
scanf("%s",s1->name);
printf("请输入添加的比赛的歌手的9个分数:");
for(sum1=0,j1=0;j1<=8;j1++)
{
scanf("%f",&(s1->score[j1]));
sum1+=(s1->score[j1]);
}
a1=0;
b1=1;
while((a1<9)&&(b1>0))
{
b1=0;
for(j1=8;j1>a1;j1--)
{
if(s1->score[j1]<s1->score[j1-1])
{temp1=s1->score[j1];
s1->score[j1]=s1->score[j1-1];
s1->score[j1-1]=temp1;
b1++;
}
}
a1++;
}
sum1=sum1-(s1->score[0])-(s1->score[8]);
s1->average=sum1/9.0;
s1->next=h->next;
h->next=s1;
}
void deletelist(gs *h)
{
gs *p3,*p4;
p3=h;
while(p3->next!=NULL)
{
if(p3->next->name=="jh")
{
p4=p3->next;
p3->next=p4->next;
free(p4);
}
else
p3=p3->next;
}
}
void paixu(gs *h)
{
gs *P,*Q,*P1,*Q1;
P=Q=Q1=h;
P1=P->next;
if(P1->average<P->average)
{ P=P1;
Q=Q1;}
Q1=P1;
P1=P1->next;
}
void display(gs *h)
{
gs *q;
int m;
q=h->next;
while(q!=NULL)
{
printf("%s\n",q->name);
printf("%.1f\n",q->average);
q=q->next;
}
}
void main()
{
gs *p;
p=createfirst();
deletelist(p);
display(p);
}
请您帮我看一下为什麽我用链表编的这个程序中deletelist(gs *h)和 paixu(gs *h)函数用不了,谢谢
急用!!!!请星期日回复