小白求解答
也不知道是什么问题总是这个样子
#include <iostream>
#include <string>
using namespace std;
const int num=6;
typedef struct Date
{
string name;
int score;
}Date;
typedef struct Student
{
Date *date;
Student *next;
}Student;
Student * Created()
{
Student *head,*node,*t;
head=(Student *)malloc(sizeof(Student));
head->date=(Date *)malloc(sizeof(Date));
node=(Student *)malloc(sizeof(Student));
node->date=(Date *)malloc(sizeof(Date));
head->date=NULL;
cout<<"第"<<num<<"个节点的数据"<<endl;
cout<<"name:";
cin>>node->date->name;
cout<<"\nscore:";
cin>>node->date->score;
head->next=node;
node->next =NULL;
for(int i=num-1;i>0;i--)
{
node=(Student *)malloc(sizeof(Student));
node->date=(Date *)malloc(sizeof(Date));
cout<<"第"<<i<<"个节点的数据"<<endl;
cout<<"name:";
cin>>node->date->name;
cout<<"\nscore:";
cin>>node->date->score;
node->next=head->next;
head->next=node;
}
t=head->next;
cout<<"遍历一遍"<<endl;
while(t!=NULL)
{
cout<<"name: "<<t->date->name<<"score: "<<t->date->score<<endl;
t=t->next;
}
return head;
}
void main()
{
Student *s=Created();
}