




免费预览已结束,剩余2页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include #include #include #include #define MAX 64typedef struct node /* 定义结构体类型dnode */int number; /* 货物编号 */char nameMAX;/* 货物名称 */int counter; /* 货物数量 */struct node *prior,*next; /* 前驱和后继指针 */dnode;dnode* head = NULL;void output_one(dnode* n)/* 输出一条记录 */printf(%dt%st%dn, n-number, n-name, n-counter);void output()/* 输出所有记录 */dnode* pos = head;if(head = NULL)return;while (pos)output_one(pos);/* 循环调用output_one */pos = pos-next;int insert()/* 插入一条数据 */dnode* pos = head;dnode* n = malloc(sizeof(dnode);n-prior = NULL;n-next = NULL;printf(请输入货物编号:);scanf(%d, &n-number);printf(请输入货物名称:);scanf(%s, n-name);printf(请输入货物数量:);scanf(%d, &n-counter);if(head=NULL)/* 如果还没有头节点,就作为头节点 */head = n;return 1;while (pos)if(pos-number n-number)/* 按顺序查找,如果找到比自己大的,就插在它前面 */if(pos-prior)pos-prior-next = n;n-prior = pos-prior;pos-prior = n;if(pos-next)pos-next-prior = n;n-next = pos;return 1;else if(pos-number = n-number)free(n);return 0;/* 有重复数据,插入不成功 */if (!pos-next)/* 如果已经到链表尾部,插入到后面 */pos-next = n;n-prior = pos;return 1;pos = pos-next;return 1;void init()while (1)/* 初始化,循环插入 */insert();printf(按任意键继续输入,按Esc停止输入n);if(getch()=27)break;int delete()/* 删除一条记录 */int num;dnode* pos = head;printf(请输入要删除的编号:);scanf(%d, &num);if(head = NULL)return 0;while (pos)if(pos-number = num)/* 找到匹配的项 */if(pos-prior)pos-prior-next = pos-next;if(pos-next)pos-next-prior = pos-prior;free(pos);return 1;pos = pos-next;return 0;/ 没找到int amend()/* 修改数量 */int num, count;dnode* pos = head;printf(请输入要修改的编号:);scanf(%d, &num);printf(请输入要修改的数量:);scanf(%d, &count);if(head = NULL)return 0;while (pos)if(pos-number = num)if (count = 0)/* 如果数量是0,就删除 */if(pos-prior)pos-prior-next = pos-next;if(pos-next)pos-next-prior = pos-prior;free(pos);return 1;pos-counter = count;return 1;pos = pos-next;return 0;void search()/* 按编号查找 */int num;dnode* pos = head;printf(请输入要查找的编号:);scanf(%d, &num);if(head = NULL)return;while (pos)if(pos-number = num)output_one(pos);/* 找到就打印 */return;pos = pos-next;void search_by_name()/* 按名称查找 */char nameMAX;dnode* pos = head;printf(请输入要查找的名称:);scanf(%s, name);if(head = NULL)return;while (pos)if(!strcmp(pos-name, name)output_one(pos);pos = pos-next;int main()init();while (1)char ch;system(cls);printf(tttti 增加新货物n);printf(ttttd 删除某种货物n);printf(tttta 修改某种货物的数量n);printf(tttts 查找指定的货物n);printf(tttto 输出存货信息n);printf(ttttq 退出程序n);ch = getch();switch (ch)case i:case I:insert();break;case d:case D:delete();break;case a:case A:amend();break;case s:case S:printf(1. 按编号查找n2. 按名称查找n);ch = getch();if(ch = 1)search()
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 汽车美容店跨界合作与联名活动协议范本
- 个人创业投资连带责任担保合同
- 2025至2030中国流变改性剂市场运营规划及前景趋势洞察报告
- 上学的出血病人护理要点
- 口服靶向药物皮疹的护理
- 2025至2030中国鼓式融化机行业产业运行态势及投资规划深度研究报告
- 认识东西南北教学课件
- 颅内积气护理查房
- 夫妻离异后子女抚养权人寿保险保障服务协议
- 二手房买卖合同签订中的合同签订与房屋质量保证
- (2025)事业单位考试公共基础知识试题库及答案详解(真题)
- 涉外劳务纠纷管理办法
- 2025年秋人教版二年级上册数学教学计划含教学进度表
- 幼儿园三重一大会议记录范文
- 小军师面试万能绝杀模板-组织管理
- midasCivil斜拉桥分析课件
- 超疏水材料课件
- 中医刮痧法诊疗操作评分标准
- 腧穴定位法课件
- 社会体育导论PTPPT课件讲义
- 学校体育学(第三版)ppt全套教学课件
评论
0/150
提交评论