




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、西安郵電學院数据结构课内实验报告题 目: 商品货架管理院系名称: 专业名称: 班 级: 学生姓名: 学号(8位): 一. 需求分析本程序的任务:设计一个商品货架管理系统,要求: (1):利用栈和队列去设计 (2):栈顶的生产日期最早,栈底的最晚,上货架的时候,是生产日期较近的在较下的的位置。(3):输入值的范围:日期大于20100302,个数小于7,必须按照由小到大的顺序输入(3):功能:要进行货架的周转二. 概要设计1 功能模块图; push()函数的流程图: 开始s1-top= -1;i=1igoodss1-tops1top+s1-goodss1-top.datetopi+真假break结
2、束循环体语句真假insert()函数的流程图: 开始s2-top = -1;s1-top!=-1&new.dates1-goodss1-top.dates2-top+;输出, s1栈中商品出栈把s1中的商品信息传递到s2中 s1-top- -真假pop(s1); pop(s2)把new的商品信息插入到s1中循环体语句return s1-top结束s2-top!=-1&new.dates2-goodss2-top.dates1-top+;输出出栈把s2中的商品信息传递到s1中 s2-top- -真假输出 s2栈中商品进栈s1循环体语句pop函数的流程图: s
3、1-top!= -1输出s1栈中的信息s1-top - -假真开始结束main()函数流程图: 开始top =push(&s1)输入要插入的信息new.date=n输出errortop=insert(&s1,new,&s2);pop(s1)结束假真 2各个模块的功能描述。 push()函数功能:往栈中输入信息 insert()函数功能:插入新的信息 pop()函数功能:输出栈中的信息。 三详细设计 数据类型struct information char name10;long date;typedef structstruct information goodssize;int top;seq
4、stack;int top;struct information new;seqstack s1,s2;伪码算法 push(): for(i=1;itop+;scanf(%s%d,,&s1-goodss1-top.date);if(s1-goodss1-top.date top = -1;for(;s1-top!=-1 & new.date s1-goodss1-top.date ; s1-top-)s2-top+;strcpy(,);s2-goodss2-top = s1-goo
5、dss1-top;s1-top+;strcpy(,n);s1-goodss1-top.date=new.date;for(;s2-top!=-1 & s2-goodss2-top.date=n;s2-top-)s1-top+;strcpy(,);s1-goodss1-top.date = s2-goodss2-top.date;pop(): for(;s1-top!=-1;s1-top-)printf(%9s%10dn,,s1-g
6、oodss1-top.date);函数调用关系图: insert();main();push();pop();四时间复杂度分析 push()函数的时间复杂度为:o(s1-top);insert()函数的时间复杂度为:o(2*s1-top+1);pop()函数的时间复杂度为:o(s1-top+1);所以整个程序的时间复杂度为:o(4*s1-top+2);五测试数据及运行结果(1): 正常的输入:red 20110302 wer 20110205 dio 20100605 ree 20100203 输入新的商品信息: die 20100708正常的运行结果: ree 出栈! dio 出栈!the
7、goods in the s1:(原栈) wer 20110205 red 20110302the goods in the s2: (辅助栈) dio 20100605 ree 20100203die进栈!dio进栈!print the information of these goods : dio 20100605die 20100708wer 20110205red 20110302(2) : 非正常的输入:乱序输入: red 20110303 wed 20110403 wds 20110506 res 20100203 输入新的商品信息: idd 20110308 非正常的运行结果:
8、 res出栈! the goods in the s1:(原栈) wds 20110506 wed 20110403 red 20110303 the goods in the s2: (辅助栈) res 20100203 idd 进栈! print the information of these goods: idd 20110308 wds 20110506 wed 20110403 red 20110303出现排序混乱的现象六调试情况,设计技巧及体会1进栈的时候应该先输入生产日期最早的的商品,而且对于生产日期应该有更精确的限制,应该使用队列解决此问题。对于非正常输入应该有所判断。2对设
9、计及调试过程的心得体会。 设计过程中使我对于对列和栈有了更好的认识,不过程序设计不够完美,考虑不全,还有些问题,所以以后应该对于程序有更好的考虑。七附录:源代码,包括注释#include#include#define size 7#define n 20100302 /数值范围确定struct information char name10;long date;typedef structstruct information goodssize;/the number of putedint top;seqstack;int push(seqstack *s1);int insert(seqs
10、tack *s1,struct information new,seqstack *s2);void pop(seqstack *s1);/进栈int push(seqstack *s1)int i;s1-top = -1;printf(n put into the goods information:( date 20100302 , number %d !)nn,size);for(i=1;itop+;scanf(%s%d,,&s1-goodss1-top.date);if(s1-goodss1-top.date top;/插入newint inser
11、t(seqstack *s1,struct information new,seqstack *s2)int m,n;s2-top = -1;for(;s1-top!=-1 & new.date s1-goodss1-top.date ; s1-top-)s2-top+;printf(%s出栈!n,);strcpy(,);/先出后进s2-goodss2-top = s1-goodss1-top;m=s1-top;n=s2-top;printf(nthe goods in the s
12、1:(原栈)n );pop(s1);printf(the goods in the s2:(辅助栈)n );pop(s2);s1-top=m;s2-top=n;s1-top+;strcpy(,n);s1-goodss1-top.date=new.date;printf(n%s进栈!n,n);for(;s2-top!=-1 & s2-goodss2-top.date=n;s2-top-)s1-top+;printf(%s进栈!n,);strcpy(,);s1-goodss1-top.date = s2-goodss2-top.date;return s1-top;/输出栈void pop(seqstack * s1)for(;s1-top!=-1;s1-top-)printf(%9s%10dn,,s1-goodss1-top.date);int main(void)int top;struct information new;seqstack s1,s2;printf(nthe goods management!n);top=push(&s1);pr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工商质量抽检管理办法
- 店家会员充值管理办法
- 哈尔滨网络车管理办法
- 城市道路挖掘管理办法
- 小组周报日报管理办法
- 定单质押贷款管理办法
- 睢宁维修资金管理办法
- 看望生病职工管理办法
- 慈善机构电梯管理办法
- 广场游乐设施管理办法
- 浙江天垣新型墙体材料有限公司年产40万立方米ALC板材项目环境影响报告
- 优生优育课件-提高生育健康水平
- 单位车辆领取免检标志委托书范本
- 人教版小学数学一年级上册全套课件合集
- 父母与高中生之间的协议书
- 2022年韶关市法院系统招聘考试真题
- 2022年江苏省射阳中等专业学校工作人员招聘考试真题
- 2023年副主任医师(副高)-中医内科学(副高)考试历年真题精华集选附答案
- 高中英语新课程标准试题含答案(四套)
- 上海六年级下册数学期中考试试卷及答案3篇(沪教版第二学期)
- 危险品储存、运输、使用安全技术交底
评论
0/150
提交评论