失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > c语言每条代码的含义 为我解释一下 代码的意思。谢谢了。

c语言每条代码的含义 为我解释一下 代码的意思。谢谢了。

时间:2023-08-21 14:05:56

相关推荐

c语言每条代码的含义 为我解释一下 代码的意思。谢谢了。

该楼层疑似违规已被系统折叠隐藏此楼查看此楼

#include

#include

#define LEN sizeof(struct student)

struct student

{long num;

intscore;

struct student *next;

};

struct student lista,listb;

int n,sum=0;

int main()

{struct student *creat(void);

struct student *insert(struct student *,struct student *);

voidprint(struct student *);

struct student *ahead,*bhead,*abh;

printf("input list a:\n");

ahead=creat();

sum=sum+n;

printf("input list b:\n");

bhead=creat();

sum=sum+n;

abh=insert(ahead,bhead);

print(abh);

return 0;

}

struct student *creat(void) //建立链表函数

{struct student *p1,*p2,*head;

n=0;

p1=p2=(struct student *)malloc(LEN);

printf("input number & scores of student:\n");

printf("if number is 0,stop inputing.\n");

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);

}

struct student *insert(struct student*ah,struct student *bh) //插入函数

{struct student * pa1,* pa2,* pb1,* pb2;

pa2=pa1=ah;

pb2=pb1=bh;

//这个do、while循环里面是什么意思,看不懂。代码题目是合并两个链表,并按学号升序排列

do

{while((pb1->num>pa1->num) && (pa1->next !=NULL))

{pa2=pa1;

pa1=pa1->next;

}

if (pb1->num<= pa1->num)

{if (ah==pa1)

ah=pb1;

else

pa2->next=pb1;

pb1=pb1->next;

pb2->next=pa1;

pa2=pb2;

pb2=pb1;

}

}while((pa1->next!=NULL) || (pa1==NULL && pb1!=NULL));

if ((pb1!=NULL) && (pb1->num>pa1->num) &&(pa1->next==NULL))

pa1->next=pb1;

return(ah);

}

如果觉得《c语言每条代码的含义 为我解释一下 代码的意思。谢谢了。》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。