TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评
- <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">#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");
- }</pre><br><br></pre></pre></pre>
|
|