#include<iostream>
using namespace std;
typedef struct node
{
int age;
char name[20];
struct node *next;
}Student;
Student* createList(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 = createList(n);
display(head);
system("pause");
return 0;
}