#include<iostream>
#include<cstdlib>
using namespace std;
struct Node
{
int num;//学生编号
char name[20];//学生姓名
float score;//学生成绩
struct Node *next;//指针域
};
Node *head=NULL;//头指针 全局变量
//创建链表,后插法入链
void CreateList(int num,char name[20],float score)
{
Node *p;
p=head;
Node *newnode;
newnode=new Node;
if(!newnode)
{
cout<<"内存分配失败,退出!"<<endl;
exit(0);
}
newnode->num=num;
strcpy(newnode->name,name);
newnode->score=score;
newnode->next=NULL;
if(head==NULL)//空链
head=newnode;
else//链表非空
{
p=head;//始终让探测指针指向链头
while(p->next!=NULL)
p=p->next;
p->next=newnode;
}
}
//输出单链表
void Display()
{
Node *p;
p=head;
cout<<"学生的信息如下:"<<endl;
cout<<"编号 姓名 分数"<<endl;