激光三维成像:看一下这个链表那里有问题。谢谢了!

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 18:58:24
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{long num;
float score;
struct student *next;
};
int n;
struct student *creat(void)
{struct student *head;
struct student *p1,p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%f",&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,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}
void print(struct student *head)
{struct student *p;
printf("\nNow,There %d records are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%ld %5.1f\n",p->num,p-score);
p=p->next;
}while(p!=NULL);
}
main()
{struct student *head,stu;
long del_num;
printf("input records:\n");
head=creat(); /*返回头指针*/
print(head); /*输出全部节点*/
printf("\ninput the deleted number:");
scanf("ld",&del_num); /*输入要删除的学号*/
head=del(head,del_num); /*删除后链表的头地址*/
print(head); /*输出全部节点*/
printf("\ninput the inserted record:");/*输入要插入的节点*/
scanf("%ld,%f",&stu.num,$&stu.score);
head=insert(head,&stu); /*返回地址*/
print(head); /*输出全部节点*/
}

第12行:struct student *p1,*p2;
p2应该为指针.
insert和del函数还没写定义.