数据结构课程设计报告

上传人:ji****72 文档编号:27374956 上传时间:2018-01-09 格式:DOCX 页数:38 大小:847.07KB
返回 下载 相关 举报
数据结构课程设计报告_第1页
第1页 / 共38页
数据结构课程设计报告_第2页
第2页 / 共38页
数据结构课程设计报告_第3页
第3页 / 共38页
数据结构课程设计报告_第4页
第4页 / 共38页
数据结构课程设计报告_第5页
第5页 / 共38页
点击查看更多>>
资源描述

《数据结构课程设计报告》由会员分享,可在线阅读,更多相关《数据结构课程设计报告(38页珍藏版)》请在金锄头文库上搜索。

1、1数据结构课程设计报告学院:信息工程专业:信息工程老师:陈占龙姓名:郝宝亮学号:20111001149班号:116112-052013年 1月 2目录控制台1.停车场管理32.个人电话号码查询系统63.排序运用124.“火烧连营”问题165.管道铺设施工的最佳方案选择19MFC1.停车场管理272.个人电话号码查询系统293.排序运用34总结自我总结383实习题目一 停车场管理【问题描述】设停车场是一个可停放 n 辆汽车的狭长通道,且只有一个大门可供汽车进出。汽车在停车场内按车辆到达时间的先后顺序,依次由北向南排列(大门在最南端,最先到达的第一辆车停放在车场的最北端),若车场内已停满n 辆汽车

2、,则后来的汽车只能在门外的便道上等候,一旦有车开走,则排在便道上的第一辆车即可开入;当停车场内某辆车要离开时,在它之后进入的车辆必须先退出车场为它让路,待该辆车开出大门外,其他车辆再按原次序进入车场,每辆停放在车场的车在它离开停车场时必须按它停留的时间长短交纳费用。试为停车场编制按上述要求进行管理的模拟程序。【设计思想】以栈模拟停车场,以队列模拟车场外的便道,按照从终端读入的输入数据序列进行模拟管理。每一组输入数据包括三个数据项:汽车“到达”或“离去”信息,汽车牌照号以及到达或离去的时刻。对每一组输入的数据进行操作后的输出信息为:若是车辆到达,则输出汽车在停车场内或便道上的停车位置;若是车辆离

3、去,则输出汽车在停车场内停留的时间和应交纳的费用(在便道上停留的时间不收费)。栈以顺序结构实现,队列以链表结构实现。需另设一个栈,临时停放为给要离去的汽车让路而从停车场推出来的汽车,也用顺序存储结构实现。输入数据按到达或离去的时刻有序。栈中每个元素表示一辆汽车,包含两个数据项:汽车的牌照号码和进入停车场的时刻。【设计表示】【代码实现】/主函数的实现#include stdafx.h#include iostream.h#include queue.h#include stack.hint main(int argc, char* argv)停车 离开判断停车场是否有空余 计算停车费用便道车辆进

4、入停车场是 否停放在便道调用入队列函数进入停车场调用入栈函数调用栈、对列的入栈、出栈、进队列、出队列函数。输入数据判断状态退出本系统4coutn;char a;coutanumtime;SeqStack s1;SeqStack s2;LinkedQueue q;s1.Push(a,num,time);coutanumtime;int time1=time;if (a=A)if (s1.Find(num)=true)cout0) /如果便道中有车,则将便道的车进入停车场q.DeQueue(a,num,time);s1.Push(a,num,time1);elsecout#include stdl

5、ib.h#include using namespace std;struct TeleNumber;istream /使编译器识别重载的运算符ostream struct TeleNumberstring name;string phoneNumber;string mobileNumber;string email;friend istream /重载friend ostream /重载(istream &is,TeleNumber &c)isc.namec.phoneNumberc.mobileNumberc.email; /输入结构体return is;ostream &operato

6、rdata.name.substr(i,i+1)0)Insert(e1,ptr-left);else if (int(e1.name.substr(i,i+1)0)int(ptr-data.name.substr(i,i+1)0)Insert(e1,ptr-right);elsereturn false;9;/删除二叉搜索树中的某结点bool BST:Remove(const string x,BSTNode *&ptr)BSTNode *temp;if (ptr!=NULL)if (int(x.substr(0,1)0)data.name.substr(0,1)0)Remove(x,ptr-

7、left);else if (int(x.substr(0,1)0)int(ptr-data.name.substr(0,1)0)Remove(x,ptr-right);else if (ptr-left!=NULL&ptr-right!=NULL)temp=ptr-right;while (temp-left!=NULL)temp=temp-left;ptr-data=temp-data;Remove(ptr-data.name,ptr-right);elsetemp=ptr;if (ptr-left=NULL)ptr=ptr-right;else ptr=ptr-left;delete t

8、emp;return true;return false;/在二叉搜索树的某个值BSTNode *BST:Search(const string x,BSTNode *ptr)if (ptr=NULL)10return NULL;else if (int(x.substr(0,1)0)data.name.substr(0,1)0)return Search(x,ptr-left);else if (int(x.substr(0,1)0)int(ptr-data.name.substr(0,1)0)return Search(x,ptr-right);elsereturn ptr; ;bool

9、BST:Modify(const string x,BSTNode *&ptr)ptr=Search(x,root);cinptr-data;return true;/主函数的实现#include #include #include #include using namespace std;#include tele.h#include BST.Hint main(int argc, char* argv)int a;string str;BST bst;BSTNode *b;coutTelei;bst.Insert(Telei);i+;fin.close();while (a!=5)cout

10、a;switch(a)case 1:coutstr;if(bst.Search(str,bst.getroot()=NULL)coutdataTelei;bst.Insert(Telei);break;case 3:coutstr;bst.Remove(str);break;case 4:coutstr;bst.Modify(str,b);break;case 5:12cout#include using namespace std;struct staff;istream ostream const int max=1000;struct staff /结构体包括职工信息string nam

11、e; /姓名string titleID; /职称编号string workingage; /工龄string age; /年龄friend istream /重载friend ostream stamax;istream &operator(istream &is,staff &c)isc.namec.titleIDc.workingagec.age;读取文本文件调用排序函数排序将排序后的信息写入文本文件14return is;ostream &operator=i;j-)if (atof(vj-1.titleID.c_str()atoi(vj.titleID.c_str()staff te

12、mp=vj-1;vj-1=vj;vj=temp;if (atof(vj-1.titleID.c_str()=atoi(vj.titleID.c_str()if (atof(vj-1.workingage.c_str()atoi(vj.workingage.c_str()staff temp=vj-1;vj-1=vj;vj=temp;if (atof(vj-1.workingage.c_str()=atoi(vj.workingage.c_str()if (atof(vj-1.age.c_str()atoi(vj.age.c_str()staff temp=vj-1;vj-1=vj;vj=tem

13、p;#include stdafx.h#include staff.h#include sort.h#include #include 15#include using namespace std;int main(int argc, char* argv)int i=0;ifstream fin(a1.txt); /将 a1.txt的内容读到结构体数组中while(!fin.eof()finstai;i+;fin.close();BubbleSort(sta,i); /调用排序函数 BubbleSortfor (int j=0;j st(40*70);void path(char str40

14、70,int x,int y)strxy=X; /将可燃点的值 A换成 Xif (strxy-1=A)temp.x=x;temp.y=y-1;st.Push(temp);if (strxy+1=A)temp.x=x;temp.y=y+1;st.Push(temp);if (strx-1y=A)temp.x=x-1;temp.y=y;输入点的坐标坐标的值为 A时,将此 A变成 X,并判断上下左右的值,若为 A,将此点压栈,并判断栈是否为空当 x39或 y69重新输入当此坐标的值为.时,重新输入否,则循环否,退顶端的元素18st.Push(temp);if (strx+1y=A)temp.x=x+1;temp.y=y;st.Push(temp);if (st.IsEmpty()=false)st.Pop(temp);path(str,temp.x,temp.y);#include stdafx.h#include stack.h#include iostream.h#include using namespace std;int main(int argc, ch

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号