#include <iostream>
using namespace std;
#include <stdio.h>
typedef struct node
{
char name[20];
int age;
struct node *next;
}Student;
Student * creatList(int n)
{
Student * head = new Student;
Student * pre = head;
for (int i = 0; i < n; i++)
{
Student* p = new Student;
printf("请输入第%d个学生的姓名和年龄:",i+1);
cin >> p->name;
cin >> p->age;
pre->next = p;
pre = p;
p->next = NULL;
}
return head;
}
void display(Student* head)
{
Student* p = head->next;
while (p != NULL)
{
cout << p->name << " " << p->age<<endl;
p = p->next;
}
}
int main()
{
int n = 2;
Student *head = creatList(n);
display(head);
system("pause");
}