TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评[cpp] view plaincopy![]() ![]()
- <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre class="cpp" name="code" code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179"><pre class="cpp" name="code" code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179"><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><pre code_snippet_id="91880" snippet_file_name="blog_20131210_3_1885640" class="cpp" name="code">/************************************************************************/
- /*
- 建立一个链表,每个结点包括的成员为:职工号、工资。用new函数开辟新结点。
- 要求链表包括5个结点,从键盘输入结点中的有效数据。然后把这些结点的数据打印出来。
- 要求用函数creat来建立链表,用list函数来输出数据。这5个职工的职工号是101,103,105,107,109。
-
- */
- /************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
-
- typedef struct student STU;
- struct student
- {
- int num;
- int GZ;
- struct student * next;
- };
- STU * creat71()
- {
- STU * p=(STU *)malloc(sizeof(STU));
- if (p==NULL)
- {
- return NULL;
- }
- else
- p->next=NULL;
- return p;
- }
- void Insert71(STU * head,int num,int GZ)
- { 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;
- p->GZ=GZ;
- last->next=p;
- p->next=NULL;
-
- }
- }
- void DeleteNode71(STU* pre,STU *cur)
- {
- pre->next=cur->next;
- free(cur);
- }
- void list71(STU *head)
- {
- STU *p=head->next;
- while(p!=NULL)
- {
- printf("%5d",p->num);
- p=p->next;
- }
- printf("\n");
- }
- void main()
- {
- STU * A=creat71();
- for (int i=0;i<5;i++)
- {
- int num;
- int GZ;
- scanf_s("%d,%d",&num,&GZ);
- Insert71(A,num,GZ);
- }
-
-
-
- list71(A);
- system("pause");
- }</pre><br><br><br></pre></pre></pre>
|
|