xt7-6-2.cpp

来自「谭浩强C程序设计习题答案」· C++ 代码 · 共 31 行

CPP
31
字号
#include <iostream>
using namespace std;
#define NULL 0     
struct student
{long num;
 float score;
 student *next;
};    
                    //定义n为全局变量,本文件模块中各函数均可使用它
student *creat(void)     //定义函数。此函数带回一个指向链表头的指针
{student *head;
 student *p1,*p2;
 int n=0;
 p1=p2=new student;       //开辟一个新单元,并使p1,p2指向它
cin>>p1->num>>p1->score;
head=NULL;
while(p1->num!=0)
{n=n+1;
 if(n==1) head=p1;
 else p2->next=p1;
 p2=p1;
 p1=new student;
 cin>>p1->num>>p1->score;
}
p2->next=NULL;
return(head);
}    



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?