注意:此页面搜索的是所有试题
题目内容
(中北大学-C语言程序设计)
下列程序用来创建一个学生数据的单向链表。创建中如输入的学号为零,则创建结束。#define LEN sizeof (struct student)
struct student
{
long num;
float score;
struct student *next;
};
int n;
struct student *creat( ) /*此creat函数带回一个链表起始地址 */
{
struct student *head, *p1, *p2;
int n=0;
p1 = p2 = (struct student *)malloc(LEN); / *开辟一个新单元*/
scanf ("%ld, %f", &p1->num, &p1->score);
head = NULL;
while(p1->num! = 0)
{
n++;
if(n = = 1)
;
else
;
p2 = p1;
p1 = ;
scanf ("%ld,%f", &p1->num, &p1->score);
}
p2->next = ;
return (head);
}
struct student
{
long num;
float score;
struct student *next;
};
int n;
struct student *creat( ) /*此creat函数带回一个链表起始地址 */
{
struct student *head, *p1, *p2;
int n=0;
p1 = p2 = (struct student *)malloc(LEN); / *开辟一个新单元*/
scanf ("%ld, %f", &p1->num, &p1->score);
head = NULL;
while(p1->num! = 0)
{
n++;
if(n = = 1)
;
else
;
p2 = p1;
p1 = ;
scanf ("%ld,%f", &p1->num, &p1->score);
}
p2->next = ;
return (head);
}
参考答案

