#创建一个链表可以根据内容来决定内存的大小,并且可以插入新结点#
#include<iostream>
#include<string>
using namespace std;
struct student {
int num=0;
string name="";
student* next=NULL;
};
int main()
{
student* head=new student;
student* p=head;
int n=0;
cout << "请输入学生个数";
cin >> n;
for (int i = 0; i < n; i++) //输入学生信息
{
cout << "请输入学生的学号和姓名" << endl;
student *note=new student;
cin >> note->num;
cin >> note->name;
p->next = note;
p = p->next;
}
p = head->next;
while (p != NULL)
{
cout << "学号:" << p->num << "姓名:" << p->name << endl;
p = p->next;
}
cout << "学生链表完成!" << endl;
//创建新节点
p = head;
cout << "请输入学生学号和姓名" << endl;
student *Newnote=new student;
cin >> Newnote->num;
cin >> Newnote->name;
while (p->next != NULL)
{
p = p->next;
}
p->next = Newnote;
p = head->next;
while (p != NULL)
{
cout << "学号:" << p->num << "姓名:" << p->name << endl;
p = p->next;
}
return 0;
}