
题目
解决代码及点评
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> typedef struct student STU; struct student { int num; char name[10]; struct student * next; }; STU * Init93() { STU * p=(STU *)malloc(sizeof(STU)); if (p==NULL) { return NULL; } else p->next=NULL; return p; } void Insert93(STU * head,int num,char * name) { STU * last=head; if (last==NULL) { return; } while(last->next!=NULL) last=last->next; STU *p=(STU *)malloc(sizeof(STU)); if (p==NULL) { return; } else { p->num=num; strcpy_s(p->name,name); last->next=p; p->next=NULL; } } void DeleteNode93(STU* pre,STU *cur) { pre->next=cur->next; free(cur); } void printfNodes93(STU *head) { STU *p=head->next; while(p!=NULL) { printf("%5d",p->num); p=p->next; } printf("\n"); } void main() { STU * A=Init93(); Insert93(A,10,"abc"); Insert93(A,30,"abc"); Insert93(A,90,"abc"); STU * B=Init93(); Insert93(B,45,"abc"); Insert93(B,100,"abc"); printfNodes93(A); printfNodes93(B); STU * p1=A->next; STU * p2=B->next; STU * tempp=A; STU * tempB=NULL; int flag=1; while(p1!=NULL&&p2!=NULL) { while (p1->num<p2->num&&p1!=NULL) { if (p1->next==NULL&&p2!=NULL) { p1->next=p2; flag=0; break; } if (p2==NULL) { flag=0; break; } p1=p1->next; tempp=tempp->next; } if (flag==0) { break; } tempB=p2->next; tempp->next=p2; p2->next=p1; p2=tempB; } printfNodes93(A); //printfNodes93(B); system("pause"); }
代码编译以及运行
由于资源上传太多,资源频道经常被锁定无法上传资源,同学们可以打开VS2013自己创建工程,步骤如下:
1)新建工程
2)选择工程
3)创建完工程如下图:
4)增加文件,右键点击项目
5)在弹出菜单里做以下选择
6)添加文件
7)拷贝代码与运行
程序运行结果
代码下载
http://download.csdn.net/detail/yincheng01/6681845
解压密码:c.itcast.cn