免费预览已结束,剩余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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年一级建造师《建筑实务》考试真题及答案
- 2025年建筑工程类一级建造师铁路工程-建筑工程(新)参考题库含答案解析
- 2025年教师资格证综合素质历年真题及答案解析
- 2023年计算机二级《Python语言程序设计》考试历年真题摘选附带答案
- 2018-421联考《申论》真题(山西乡镇卷)及参考答案
- 2025年木材干燥学试题及答案
- 2025年库房物料防尘试题及答案
- 2025年标准海南c证安全员考试题库及答案
- 2025年小学语文一年级上册期末试题及答案
- 初级银行考试真题及答案(2篇)
- 林木分子标记辅助育种
- 慢性化脓性中耳炎教学查房课件
- 无能力抚养孩子委托他人抚养委托书
- 脚手架验收表
- 龙虎山正一日诵早晚课
- 新媒体数据分析与应用完整PPT全套教学课件
- 图书馆中级职称专业技术资格考试题库
- 影像记忆之记忆宫殿-抽象词语转换训练
- JGJ142-2004《地面辐射供暖技术规程》条文说明
- 青海省干部履历表实用文档
- 电瓶车维修费用明细
评论
0/150
提交评论