在线等一道简单C语言题目的源代码

来源:百度知道 编辑:UC知道 时间:2024/05/10 06:23:19
设学生记录由姓名,成绩组成。设计链表数据结构,实现建立链表,遍历链表,向链表插入结点,删除指定结点等操作

我在线等答案,答案好我会加分的!快!

#include <stdio.h>
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{long num;
int score; struct student *next;
};
int n;
struct student *creat()
{ struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=( struct student*) malloc(LEN);
scanf("%ld,%d",&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=(struct student*)malloc(LEN);
scanf("%ld,%d",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}

void print(struct student *head)
{ struct student *p;
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
do