C语言系统.doc_第1页
C语言系统.doc_第2页
C语言系统.doc_第3页
C语言系统.doc_第4页
C语言系统.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

#include #include #include #define LEN sizeof(struct worker)struct worker /num为工号,score为工作量long num;float score;struct worker *next;int n; /全局变量-总人数(总结点数)/*建立链表函数*struct worker *creat(void)struct worker *head;struct worker *p1,*p2;n=0;p1=p2=(struct worker *)malloc(LEN); /开辟一个新结点scanf(%ld:%f,&p1-num,&p1-score);head=NULL;while(p1-num != 0) /p1不断更新指向新开辟的节点,p2不断更新指向新结点之前一个结点,建立链表关系n=n+1;if(n=1) head=p1;else p2-next=p1;p2=p1;p1=(struct worker *)malloc(LEN);scanf(%ld:%f,&p1-num,&p1-score);p2-next=NULL;return(head);/*输出链表函数*void print(struct worker *head) struct worker *p,*temp;long nums100=0,T_num;int i=1,j=1;/i为名次;j为名次对应的人数int k,x,y;/;k,x,y为循环变量p=head;printf(nNow,Totall %d records are:nn,n);if(head!=NULL)do temp = p-next;if(temp=NULL)numsj=p-num;printf(nn名次:%d 工作量:%f 人数:%dn,i,p-score,j);printf(工号是:); for(x=1;xj;x+)for(y=x+1;y numsy)T_num = numsx;numsx = numsy;numsy = T_num;for(k=1;kscore = p-score) numsj=p-num;j+;elsenumsj=p-num;printf(nn名次:%d 工作量:%f 人数:%dn,i,p-score,j);printf(工号是:);for(x=1;xj;x+)for(y=x+1;y numsy)T_num = numsx;numsx = numsy;numsy = T_num;for(k=1;knext; /更新pwhile(p != NULL);/*累积数据函数*void plus(struct worker *head,struct worker *P_ker)struct worker *p;for(p = head;p != NULL;p = p-next)if(p-num=P_ker-num) p-score=p-score + P_ker-score;printf(成功累加更新%ld数据!nn,P_ker-num);system(pause);/*删除结点函数*struct worker *del(struct worker *head,long num)struct worker *p1,*p2;if(head=NULL) printf(nlist null! n);goto end;p1 = head;while(num != p1-num&p1-next!=NULL) /p1指向的不是所要的结点,并且后面还有结点p2 = p1;p1 = p1-next; /p1指向下一个结点,p2更新为上一个p1 if(num = p1-num)if(p1 = head) head = p1-next;else p2-next = p1-next;printf(delete:%ldn,num);n = n - 1;printf(成功删除%ld数据!nn,num);system(pause);else printf(%ld 没有被找到! nn,num); /程序的鲁棒性end:return(head);/*插入结点函数*struct worker *insert(struct worker *head,struct worker *stud)struct worker *p0,*p1,*p2;p1 = head; /p1指向第一个结点p0 = stud; /p0指向待插入结点if(head = NULL)head = p0;p0-next = NULL;else /实现按num大小顺序插入while( (p0-num p1-num) & (p1-next != NULL) )p2 = p1;p1 = p1-next;if(p0-num num)if(head = p1) head = p0;else p2-next = p0;p0-next = p1;elsep1-next = p0;p0-next = NULL;n = n + 1;printf(已成功插入数据 %ldnn,stud-num);system(pause);return(head);/*链表排序函数*struct worker *sort(struct worker *head)struct worker *p1,*p2,*tmp_p,*pPre1,*pPre2,*tmp_pPre2,*pTmp,*headPre;float tmp_fScore;int i,j;headPre = (struct worker *)malloc(LEN);headPre-next = head;for (i =1; i n; i+)p1 = head; pPre1 = headPre;for (j =1; j next; pPre1 = pPre1-next;tmp_p = p1;tmp_fScore = p1-score;for (pPre2 = p1, p2 = p1-next; p2 != NULL;p2 = p2-next,pPre2 = pPre2-next)if (tmp_fScore score)tmp_p = p2;tmp_pPre2 = pPre2;tmp_fScore = p2-score;if(p1 != tmp_p) /jiao huan if(p1-next != tmp_p)pTmp = p1-next;p1-next = tmp_p-next;tmp_p-next = pTmp;pTmp = pPre1-next;pPre1-next = tmp_pPre2-next;tmp_pPre2-next = pTmp;elsepTmp = p1-next;p1-next = tmp_p-next;tmp_p-next = pPre1-next;pPre1-next= pTmp;printf(链表已经按工作量从大到小的顺序调整完毕!nn);return(headPre-next);/*主界面显示函数*void interface(void)printf(n);printf(* 欢迎进入职工工作量统计系统 *n);printf(n);printf( 主菜单 n);printf( n);printf(1.新建数据链表 - 请按 B Bulid A New n);printf( n);printf(2.插入一个数据 - 请按 I Insert Data n);printf( n);printf(3.删除一个数据 - 请按 D Delete Data n);printf( n);printf(4.统计分析链表 - 请按 A Analyse Data n);printf( n);printf(5.显示排序结果 - 请按 P Print Data n);printf( n);printf(6.重新累积数据 - 请按 + Plus Data n);printf( n);printf(7.退出统计系统 - 请按 E Esc system n);printf( n);printf( (涂超凡 20085056) n); printf( n);printf(n);void main()struct worker *head,*I_ker,*P_ker;long D_num;char flag = 0; /菜单选择标识while(flag != E)system(cls);interface();printf(请输入子菜单选择:);scanf(%c,&flag);switch(flag)caseB:system(cls);printf(新建数据链表nn);printf(输入格式 工号:工作量 工号为0结束nn);head=creat();/调用函数getchar();/把换行符用掉!break;caseI:system(cls);printf(插入一个数据nn);I_ker = (struct worker *)malloc(LEN); /为插入数据开辟空间printf(输入插入数据 工号:工作量 nn);scanf(%ld:%f,&I_ker-num,&I_ker-score);getchar();/把换行符用掉!head=insert(head,I_ker);/调用函数break;caseD:system(cls);printf(删除一个数据nn);printf(输入要删除数据的工号nn);scanf(%ld,&D_num);getchar();/把换行符用掉!head=del(head,D_num);/调用函数break;caseA:system(cls);printf(统计分析链表nn);head=sort(head);/调用函数system(pause);break;caseP:system(cls);printf(显示排序结果nn);print(head);/调用函数system(pause);break;case+:system(cls);printf(重新累积数据nn);P_ker = (struct worker *)malloc(LEN); /为插入数据开辟空间printf(输入需要累积数据的 工号:工作量 nn);scanf(%ld:%f,&P_ker-num,&P_ker-score);getchar();/把换行符用掉!plus(head,P_ker);/调用函数break;system(pause);#includestdio.h struct gren int gonghao; char name20; int gzliang; int age; char zhuzhi20; per20,*p=per;void main()char ch,c;int i;void fun(char ch);char s20=123456;fun( ch);printf(请输入字母:);c=getchar();while(c!=H)if (c=A) for(i=0;i20;i+)printf(请输入第i+1个人的姓名:,i);scanf(%s,&);printf(请输入第i+1各人的年龄:,i);scanf(%d,&peri.age); void fun(char ch) printf(*欢迎查询工人工作系统*n); printf(*主界面*n); printf(* 输入姓名请按A: *n); printf(* 输入性别请

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论