|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <malloc.h>
#define LEN sizeof(struct student)
struct student
{
int num;
int score;
struct student *next;
};
int n=0;
struct student *creat()//创建链表
{
struct student *head;
struct student *p1,*p2;
p1=p2=(struct student *)malloc(LEN);
scanf("%d,%d",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{
n++;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%d,%d",&p1->num,&p1->score);
}
p2->next=NULL;
return head;
}
void print(struct student *head)//输出函数
{
struct student *p;
p=head;
if(head!=NULL)
{
while(p!=NULL)
{
printf("%-6d%5d\n",p->num,p->score);
p=p->next;
}
}
}
void main()
{
struct student *a,*b;
printf("input LL a here:\n");
a=creat();
printf("input LL b here:\n");
b=creat();
printf("LL a:\n");
print(a);
printf("LL b:\n");
print(b);
}
得到这个结果,不知道为什么链表b无法输出呢?是输入函数的问题还是输出函数的问题?
|
|