为什么老是出错?请帮我分析一下错误

[复制链接]
查看11 | 回复1 | 2011-4-23 07:17:55 | 显示全部楼层 |阅读模式
//成绩排名
#includeiostream.h
#includestring.h
struct chengji{
char name[10];
float fenshu;
chengji *next;
};
void main()
{
chengji *head;int n;
void create(chengji*
cout\"请输入数据的个数N:\";cinn;
create(head,n);
void f(chengji *
f(head,n);
void out(chengji*
out(head);
}
void create(chengji *
h=new chengji;p=h;
cout\"请输入\"m\"个数据(包括姓名和分数)\\n\";
float x;char a[10];cinax;p-fenshu=x;strcpy(p-name,a);
for(int i=1;im-1;i)
{
cinax;pp=new chengji;strcpy(pp-name,a);pp-fenshu=x;
p-next=pp;p=pp;
}p-next=NULL;
}
void f(chengji *float y;
chengji *f1,*f2;
for(int j=1;j=mm;j)
{
f1=hh;
for(int k=1;kmm;k)
{
f2=f1-next;
if(f1-fenshuf2-fenshu)
{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 *int kk=1;
do{cout\"第\"kk\"名为:\"h2-name\"\"h2-fenshuendl;h2=h2-next;}
while(h2-next!=NULL);
}
回复

使用道具 举报

千问 | 2011-4-23 07:17:55 | 显示全部楼层
<pre id=\"best-answer-content\" class=\"reply-text mb10\">帮你修改运行过了,好好看看吧。
#includeiostream.h
#includestring.h
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;
cout\"请输入数据的个数N:\";cinn;
head=create(n);
head=f(head,n);
cout\"成绩排序输出班级:\"endl;
out(head,n);
}
chengji *create(int m){
//返回一个头结点以获得链表
chengji *p,*pp,*h;


cout\"请输入\"m\"个数据(包括姓名和分数)\\n\";
//float x;char a[10];cinax;p-fenshu=x;strcpy(p-name,a); //这里直接访问结构体中数据成员就可以了,不用再定义

for(int i=0;im;i)
{
p=new chengji;
//cinax;pp=new chengji;strcpy(pp-name,a);pp-fenshu=x;
if(i==0)
//创建头结点数据
{
h=p;
cout\"输入姓名:\";
cinh-name;
cout\"输入分数:\";
cinh-fenshu;}
else
{

pp-next=p;
cout\"输入姓名:\";
cinp-name;
cout\"输入分数:\";
cinp-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;jmm;j)
{
f1=hh;
for(int k=0;kmm-j;k)
{
f2=f1;
f1=f1-next;
if(f1-fenshuf2-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;in;i)
{

cout\"姓名:\"p1-name\" 分数:\"p1-fenshuendl;
p1=p1-next;
}
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行