未完成,更新中
#include<iostream>
#include<cstdio>
using namespace std;
struct student
{
int num;
float fen;
student *next;
};
student *creat(int n)//需要建立链表的长度
{
student *head=NULL;
student *pnew,*pend;
pnew=pend=NULL;//初始化链表
pnew=new student;
cout<<"input num and fen"<<endl;
scanf("%d%f",&pnew->num,&pnew->fen);
pend=pnew;
head=pnew;
pend->next=NULL;
for(int i=2;i<=n;i++)
{
pnew=new student;
scanf("%d%f",&pnew->num,&pnew->fen);
pend->next=pnew;
pend=pnew;
}
pend->next=NULL;
return head;
};
void Print(student *head)//输出数据
{
int d=1;
student *temp=head;
while(temp!=NULL)
{
cout<<"第"<<d++<<"位学生"<<"num="<<temp->num<<" "<<"fen="<<temp->fen<<endl;
temp=temp->next;
}
}
int main()
{
int n;
cout<<"请输入需要建立链表的长度"<<endl;
cin>>n;
student *p,*ins;
p= creat(n);
Print(p);
cout<<"insert student"<<endl;
ins=new student;
cin>>ins->num>>ins->fen;
}