




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
m_book.c#include struct node char name10;int price;char pub15;extern struct node *add(),*del(struct node *);extern struct node *load(),*mhdel(struct node *);/*/* 函数功能:显示菜单,选择菜单 */* 输入参数:无 */* 函数输出:选择的菜单序号 */*/int menu_select()int cn=0;printf( *n);printf(tt 1. Add a bookn);printf(tt 2. Display book libraryn);printf(tt 3. Query a bookn);printf(tt 4. Delete a bookn);printf(tt 5. Save to diskn);printf(tt 6. Load from disk n);printf(tt 7. Mohu searchn);printf(tt 8. Mohu deleten);printf(tt 0. Exitn);printf(t*n);printf(n Input(08): );for(; ;) scanf(%d,&cn);if (cn8) printf(Error ! Input again(16):);elsebreak;return cn;void main(void)struct node *head=NULL;for(; ;) clrscr();switch(menu_select()case 1: head=add(head);break;case 2: print(head);break;case 3: search(head);break;case 4: head= del(head);break;case 5: save(head);break;case 6: head=load();break;case 7: mhsearch(head);break;case 8: head=mhdel(head);break;case 0: exit(0);s_book.c#include #include #include struct node char name10; float price; char pub15; struct node *link;struct node *add(struct node *head ) ; /* 函数功能:创建结点,输入结点数据 */void print(struct node *head); /* 函数功能:链表输出 */void save(struct node *head); /* 函数功能:链表存储 */void search(struct node *head); /* 函数功能:链表结点查找 */struct node *del(struct node *head); /* 函数功能:结点删除 */struct node *load(void); /* 函数功能:从文件中读入数据,创建链表 */struct node *mhdel(struct node *head); /* 函数功能:结点模糊删除 */void mhsearch(struct node *head); /* 函数功能:链表结点模糊查找 */*/* 函数功能:创建结点,输入结点数据 */* 输入参数:链表头指针 */* 函数输出:链表头指针 */*/struct node *add(struct node *head ) int i;float jg;struct node *p, *pnew;pnew=(struct node *)malloc(sizeof(struct node); printf(Please input book name,price,publishern);printf(name:);scanf(%s,pnew-name);printf(price:);scanf(%f,&jg);pnew-price=jg;printf(publisher:);scanf(%s,pnew-pub);pnew-link=NULL;if (head=NULL)return (pnew);p=head;while (p-link!=NULL) /* 找到尾结点 */p=p-link;p-link=pnew;return (head);/*/* 函数功能:链表输出 */* 输入参数:链表头指针 */* 函数输出:无 */*/void print(struct node *head) struct node *p;p=head;printf(nametpricetpublishern);while (p!=NULL)printf(%st%-5.2ft%-sn,p-name,p-price,p-pub);p=p-link;printf(nttPress any keys!);getch();/*/* 函数功能:链表存储 */* 输入参数:链表头指针 */* 函数输出:无 */*/void save(struct node *head) FILE *fp;struct node *p;if (fp=fopen(library,wb)=NULL) printf(Cant open file!n);exit(1);p=head;while (p!=NULL)fwrite(p,sizeof(struct node),1,fp);p=p-link;fclose(fp);/*/* 函数功能:从文件中读入数据,创建链表 */* 输入参数:无 */* 函数输出:链表头指针 */*/struct node *load(void)FILE *fp;struct node *p,*pnew,*phead;if (fp=fopen(library,rb)=NULL) printf(Cant open file!n);exit(1);pnew=(struct node *)malloc(sizeof(struct node);fread(pnew, sizeof(struct node),1,fp);pnew-link=NULL;phead=pnew;p=pnew;while (!feof(fp) pnew=(struct node *)malloc(sizeof(struct node);if (1!=fread(pnew, sizeof(struct node),1,fp) break;pnew-link=NULL;p-link=pnew;p=p-link;fclose(fp);return(phead);/*/* 函数功能:链表结点查找 */* 输入参数:链表头指针 */* 函数输出:无 */*/void search(struct node *head)char sname15;struct node *p;printf(Please input book namen);printf(name:);scanf(%s,sname);p=head;while (p!=NULL) if (strcmp(p-name,sname)=0)printf( name price publshiern);printf(Book Found: %s %5.2f %sn,p-name,p-price,p-pub);printf(nttPress any keys!);getch();return;p=p-link;printf(Book Not Exist!n);printf(nttPress any keys !); getch();/*/* 函数功能:结点删除 */* 输入参数:链表头指针 */* 函数输出:返回链表头指针 */*/struct node *del(struct node *head)char sn15,s;int flag=0;struct node *p,*q;printf(Please input book namen);printf(name:);scanf(%s,sn);p=head;while(p!=NULL)while(p!=NULL &(strcmp(p-name,sn)!=0) q=p;p=p-link;if(strcmp(p-name,sn)=0)& p!=NULL)flag=1;printf( name price publshiern);printf(Book Found: %s %5.2f %sn,p-name,p-price,p-pub);printf(Do you want to del this book(y/n);scanf(n%c,&s);if(s=y | s=Y)if(p=head)head=p-link;else q-link=p-link;free(p);printf(This book is deleted!n);printf(nttPress any keys !);getch();elseprintf(nThis book not delete!n);printf(nttPress any keys!);getch();return head;else if(flag!=1) printf(nNOT found!);printf(nttPress any key!);getch();break;if(p!=NULL) p=p-link; return head;void mhsearch(struct node *head)char s15;int flag=0;struct node *p;printf(Please input book namen);printf(name:);scanf(%s,s);p=head;while(p!=NULL)while(p!=NULL & (strstr(p-name,s)=NULL) p=p-link;if(strstr(p-name,s)!=NULL) printf( name price publshiern);printf(Book Found: %s %5.2f %sn,p-name,p-price,p-pub);flag=1;getch();else if(flag!=1) printf(nNOT found!);printf(nttPress any key!);getch();if(p!=NULL) p=p-link; struct node *mhdel(struct node *head)char sn15,s;int flag=0;struct node *p,*q;printf(Please input book namen);printf(name:);scanf(%s,sn);p=head;while(p!=NULL)while(p!=NULL &(strstr(p-name,sn)=NULL) q=p;p=p-link;if(strcmp(p-name,sn)!=NULL)& p!=NULL)flag=1;printf( name price publshiern);printf(Book Found: %s %5.2f %sn,p-name,p-price,p-pub);printf(Do you want to del this book(y/n);scanf(n%c,&s);if(s=y | s=Y)if(p=head)head=p-link;else q-link=p-lin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 房地产开发中的伦理问题探讨
- 病人饮食禁忌与膳食调养的注意事项
- 环境灾害应急响应预案培训监督机制重点基础知识点归纳
- 东渐数能童元柏-固态电解质的发展趋势及制备
- 实施精益管理提升项目效益
- 护理中的协作沟通
- 亚洲女性的彩妆 挥洒出她们的光芒
- 精致眼线 细细眼线勾勒迷人眼妆
- 城市轨道交通BIM设计实例解析
- 档案库防潮层密封性检测技术报告
- 漫画版《幼儿园入学准备教育指导要点》
- 蓝色卡通风毕业典礼PPT模板
- 水电站计算机监控方式的演变历程
- 2023年运动康复期末复习-运动损伤学(运动康复专业)考试历年高频考点真题演练附带含答案
- 登高作业证题库
- 2022年06月广东揭阳市惠来县退役军人事务局公开招聘基层退役军人专职服务人员3人笔试题库含答案解析
- 2023-2024学年山东省潍坊市小学语文 2023-2024学年六年级语文期末试卷期末评估试卷
- 活髓保存治疗间接盖髓术
- 国开电大本科《管理英语3》机考总题库
- 2022年河南中考生物真题试卷
- 2023年江苏连云港市金融控股集团有限公司招聘笔试题库及答案解析
评论
0/150
提交评论