标题:[求助]创建单链表的问题
取消只看楼主
爱上夜
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2006-9-12
 问题点数:0 回复次数:0 
[求助]创建单链表的问题
我先定义一个结构体,然后编写了一个建立学生管理信息的函数.
可在调用此函数时如果录入三个学生信息只能输出两个,录入两个只能输出一个
输出函数没问题,估计是struct stu *con(unsigned n)函数出问题了.请教各位,给看看!谢谢!!!

typedef struct stu{
unsigned no;
char name[10];
float sc[2];
unsigned age;
char sex[10];
struct stu *next;
}stu;
struct stu *con(unsigned n) //建立学生管理系统
{
stu *p,*q,*h;
char ch;
int x;
p=new struct stu;
cout<<"***********************************************************************"<<endl;
cout<<" 请输入学生信息 "<<endl;
cout<<"***********************************************************************"<<endl;
h=q=p;
for(unsigned i=0;i<n;i++)
{ cout<<"请输入学号:"<<endl;
cin>>p->no;
cout<<"请输入姓名:"<<endl;
cin>>p->name;
cout<<"请输入英语成绩:"<<endl;
cin>>p->sc[0];
cout<<"请输入C++成绩:"<<endl;
cin>>p->sc[1];
cout<<"请输入年龄:"<<endl;
cin>>p->age;
cout<<"请输入性别b/g:"<<endl;
cin>>ch;
for(x=0;x<100;x++)
{
if(ch=='b')
{ strcpy(p->sex,"男");
break;}
if(ch=='g')
{ strcpy(p->sex,"女");
break;}
if(ch!='b'&&ch!='g')
{ cout<<"输入有误,请重新输入:"<<endl;
cout<<"请输入性别b/g:"<<endl;
cin>>ch;
}
}
q->next=p;
q=p;
p=new struct stu;
}
delete p;
p->next=0;
return(h);
}
搜索更多相关主题的帖子: 单链 
2006-12-16 17:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-109932-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.326708 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved