好文档 - 专业文书写作范文服务资料分享网站

《C语言程序设计》课后习题答案(第四版)谭浩强23019

天下 分享 时间: 加入收藏 我要投稿 点赞

p2->next=NULL; return(head); }

struct student *del(struct student *head,long num) {struct student *p1,*p2; if (head==NULL)

{printf(\ return(head); }

p1=head;

while(num!=p1->num && p1->next!=NULL) {p2=p1;p1=p1->next;} if(num==p1->num) {if(p1==head)head=p1->next; else p2->next=p1->next; printf(\ n=n-1; }

else printf(\ return(head); }

struct student *insert(struct student *head, struct student *stud) {struct student *p0,*p1,*p2; p1=head;

p0=stud; if(head==NULL) {head=p0; p0->next=NULL;} else

{while((p0->num>p1->num) && (p1->next!=NULL)) {p2=p1; p1=p1->next; }

if(p0->num<=p1->num) {if(head==p1) head=p0; else p2->next=p0; p0->next=p1; } else

{p1->next=p0; p0->next=NULL;} }

n=n+1; return(head);

}

void print(struct student *head) {struct student *p;

printf(\ p=head;

if(head!=NULL) do {printf(\ p=p->next;

}while(p!=NULL); }

9-9-3

#include #include

#define LEN sizeof(struct student) struct student {long num;

float score; struct student *next; }; int n;

int main()

{struct student *creat();

void print(struct student *);

struct student *del(struct student *,long);

struct student *insert(struct student *, struct student *); struct student *head,*stu; long del_num;

printf(\ head=creat(); print (head);

printf(\ scanf(\ while (del_num!=0)

{head=del(head,del_num); print (head);

printf (\ scanf(\

printf(\ stu=(struct student *) malloc(LEN);

scanf(\ while(stu->num!=0)

{head=insert(head,stu); print(head); printf(\ stu=(struct student *)malloc(LEN); scanf(\ } return 0; }

struct student *creat() {struct student *head;

struct student *p1,*p2; n=0;

p1=p2=( struct student*) malloc(LEN); scanf(\ 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(\ }

p2->next=NULL; return(head); }

struct student *del(struct student *head,long num) {struct student *p1,*p2; if (head==NULL)

{printf(\ p1=head; while(num!=p1->num && p1->next!=NULL) {p2=p1;p1=p1->next;} if(num==p1->num)

{if(p1==head)head=p1->next; else p2->next=p1->next; printf(\ n=n-1; } else printf(\

return(head); }

struct student *insert(struct student *head, struct student *stud) {struct student *p0,*p1,*p2; p1=head; p0=stud; if(head==NULL)

{head=p0; p0->next=NULL;} else {while((p0->num>p1->num) && (p1->next!=NULL)) {p2=p1; p1=p1->next; }

if(p0->num<=p1->num) {if(head==p1) head=p0; else p2->next=p0; p0->next=p1;} else

{p1->next=p0; p0->next=NULL;} } n=n+1; return(head); }

void print(struct student *head) {struct student *p; printf(\ p=head; if(head!=NULL) do {printf(\ p=p->next; }while(p!=NULL); } 9-10

#include #include

#define LEN sizeof(struct student)

struct student {long num;

int score;

struct student *next; };

struct student lista,listb; int n,sum=0;

int main()

{struct student *creat(void);

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

struct student *ahead,*bhead,*abh; printf(\ ahead=creat(); sum=sum+n;

printf(\ 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(\ printf(\ scanf(\ 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(\ }

p2->next=NULL; return(head); }

《C语言程序设计》课后习题答案(第四版)谭浩强23019

p2->next=NULL;return(head);}structstudent*del(structstudent*head,longnum){structstudent*p1,*p2;if(head==NULL){printf(\return(head);
推荐度:
点击下载文档文档为doc格式
87azb13lxw6x2111f20r4n7xz5ee5l00bm8
领取福利

微信扫码领取福利

微信扫码分享