为什么老是出错?请帮我分析一下错误//成绩排名#include#includestruct chengji{char name[10];float fenshu;chengji *next;};void main(){chengji *head;int n;void create(chengji*&,int);coutn;create(head,n);void f(chengji *&,int);f(head,n);

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/02 17:16:13
为什么老是出错?请帮我分析一下错误//成绩排名#include#includestruct chengji{char name[10];float fenshu;chengji *next;};void main(){chengji *head;int n;void create(chengji*&,int);coutn;create(head,n);void f(chengji *&,int);f(head,n);

为什么老是出错?请帮我分析一下错误//成绩排名#include#includestruct chengji{char name[10];float fenshu;chengji *next;};void main(){chengji *head;int n;void create(chengji*&,int);coutn;create(head,n);void f(chengji *&,int);f(head,n);
为什么老是出错?请帮我分析一下错误
//成绩排名
#include
#include
struct chengji{
char name[10];
float fenshu;
chengji *next;
};
void main()
{
chengji *head;int n;
void create(chengji*&,int);
coutn;
create(head,n);
void f(chengji *&,int);
f(head,n);
void out(chengji*&);
out(head);
}
void create(chengji *&h,int m){ //对于只要3、4个成绩的情况就没有必要用程序排名
chengji *p,*pp;
h=new chengji;p=h;
coutname,a);
for(int i=1;i>a>>x;pp=new chengji;strcpy(pp->name,a);pp->fenshu=x;
p->next=pp;p=pp;
}p->next=NULL;
}
void f(chengji *&hh,int mm){
char aa[10];float y;
chengji *f1,*f2;
for(int j=1;jfenshufenshu)
{strcpy(aa,f1->name);
strcpy(f1->name,f2->name);
strcpy(f2->name,aa);
y=f1->fenshu;
f1->fenshu=f2->fenshu;
f2->fenshu=y;}
f1=f2;
}
}
}
void out(chengji *&h1){
chengji *h2=h1;int kk=1;
do{cout

为什么老是出错?请帮我分析一下错误//成绩排名#include#includestruct chengji{char name[10];float fenshu;chengji *next;};void main(){chengji *head;int n;void create(chengji*&,int);coutn;create(head,n);void f(chengji *&,int);f(head,n);
帮你修改运行过了,好好看看吧.
#include
#include
struct chengji{
char name[10];
float fenshu;
chengji *next;
};
chengji *create(int m); //子函数定义放在主函数后面定义,主义要先声明
chengji *f(chengji *hh,int mm);
void out(chengji *h1,int n);
void main()
{
chengji *head;int n;
coutn;
head=create(n);
head=f(head,n);
coutname,a);pp->fenshu=x;
if(i==0) //创建头结点数据
{
h=p;
couth->name;
couth->fenshu;}
else
{
pp->next=p;
coutp->name;
coutp->fenshu;
}
pp=p;
}
pp->next=NULL;
return h;
}
chengji *f(chengji *hh,int mm) //成绩排序,返回排序后链表头结点
{
char aa[10];float y;
chengji *f1,*f2,*f3=hh;
for(int j=1;jfenshu>f2->fenshu)
{strcpy(aa,f1->name);
strcpy(f1->name,f2->name);
strcpy(f2->name,aa);
y=f1->fenshu;
f1->fenshu=f2->fenshu;
f2->fenshu=y;}
}
}
return f3;
}
void out(chengji *head,int n) //输出班级
{
chengji *p1=head;
for(int i=0;i