关于双向循环链表生成的问题

aleyn 2010-03-28 10:56:21
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
typedef struct Student
{
int num;
char *name;
double math,computer,chinese,sum;
struct Student *prior,*next;
}Stu;
void CreateList(Stu *&L) //建立双向循环链表
{
Stu *p,*q=L;
int i,n;
L=new Stu[sizeof(Stu)];
L->prior=L->next=L;
cout<<"输入你要录入学生信息的人数:";
cin>>n;
cout<<endl;
for(i=0;i<n;i++)
{
p=new Stu[sizeof(Stu)];
p->prior=p->next=NULL;
p->name=new char[10];
cout<<"请输入学生的姓名:";
cin>>p->name;
cout<<endl;
cout<<"请输入学生的学号:";
cin>>p->num;
cout<<"请输入该学生的3科成绩:";
cin>>p->math;
cin>>p->computer;
cin>>p->chinese;
p->sum=p->math+p->computer+p->chinese;
//////////////////////////////////////////////////////
q->next=p;
p->prior=q;
p->next=L;
L->prior=p;
q=p;
//////////////////////////////////////////////////////
}
}

void main()
{
Stu *L;
CreateList(L);
}
...全文
75 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
aleyn 2010-03-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 vshuang 的回复:]
C/C++ code

Stu *p,*q=L;
int i,n;
L=new Stu[sizeof(Stu)];
L->prior=L->next=L;


改成

C/C++ code

int i,n;
L=new Stu[sizeof(Stu)];
L->prior=L->next=L;
Stu *p,*q=L;


因为一开始的时候L指针指向的地方是不……
[/Quote]




非常感谢!
  • 打赏
  • 举报
回复

Stu *p,*q=L;
int i,n;
L=new Stu[sizeof(Stu)];
L->prior=L->next=L;

改成

int i,n;
L=new Stu[sizeof(Stu)];
L->prior=L->next=L;
Stu *p,*q=L;

因为一开始的时候L指针指向的地方是不确定的
aleyn 2010-03-28
  • 打赏
  • 举报
回复
在线等,望高手快点帮忙解决一下

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧