




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C+类树医院设施管理树的应用,统计任意两个结点之间的结点个数,支出给定结点的子结点,浏览整个医院的结构,C+,类 ,树,医院设施管理,C+,类#include #include #include #include#include #include using namespace std;class hosnodepublic:string name;int num;hosnode(string n = NULL, int number = 0);string Name();int Num();friend ostream& operator(ostream& out, hosnode& node);hosnode:hosnode(string n, int number)name = n;num = number;string hosnode:Name()return name;int hosnode:Num()return num;ostream& operator(ostream& out, hosnode& node)out | setiosflags(ios_base:left) setw(8) | resetiosflags(ios_base:left) setw(8) node.num |;return out;class treenode/treenode* parent; /父结点public:hosnode value;treenode* pc; /最左边子结点treenode* ls; /左兄弟节点treenode* rs; /右兄弟节点treenode(hosnode m_value);/*void setvalue(hosnode m_value);void setchild(treenode* pointer);void setsibling(treenode* pointer);void insertfirst(treenode* node);void insertnext(treenode* node);void print();*/void visit();treenode:treenode(hosnode m_value) :value(m_value)pc = NULL;ls = NULL;rs = NULL;void treenode:visit()cout value pc = tmp2;elsetmp1 = find(parent);if (tmp1)tmp2 = new treenode(*value);if (tmp1-pc = NULL)tmp1-pc = tmp2;elsetmp3 = tmp1-pc;while (tmp3-ls)tmp3 = tmp3-ls;tmp3-ls = tmp2;treenode* tree:Parent(treenode* cur)if (!cur)return NULL;elsetreenode *pointer = root, *tmp;queue nqueue;if (pointer)nqueue.push(pointer);while (!nqueue.empty()pointer = nqueue.front();tmp = pointer-pc;if (tmp != NULL)if (tmp-value).Name() = (cur-value).Name()return pointer;elsetmp = tmp-ls;if (tmp != NULL)while (tmp-value).name != (cur-value).name)tmp = tmp-ls;if (!tmp)break;if (tmp != NULL)return pointer;nqueue.pop();if (pointer-pc != NULL)nqueue.push(pointer-pc);tmp = pointer-pc-ls;while (tmp)nqueue.push(tmp);tmp = tmp-ls;return NULL;treenode* tree:find(string cur)treenode *pointer = root, *tmp;queue nqueue;if (pointer)nqueue.push(pointer);while (!nqueue.empty()pointer = nqueue.front();if (pointer-value).Name() = cur)return pointer;nqueue.pop();if (pointer-pc != NULL)nqueue.push(pointer-pc);tmp = pointer-pc-ls;while (tmp)nqueue.push(tmp);tmp = tmp-ls;return NULL;void tree:with(treenode* root)treenode *pointer = root, *tmp;int n = 0;queue nqueue;cout -n;cout | 名称 | 数量 |n;cout );cout | setiosflags(ios_base:left) setw(8) setw(2) | setw(8) n resetiosflags(ios_base:left) | endl;cout pc != NULL)nqueue.push(pointer-pc);tmp = pointer-pc-ls;while (tmp)nqueue.push(tmp);tmp = tmp-ls;int tree:count(string gparent, string child)int n = 1;if (find(gparent) = NULL | find(child) = NULL)return 0;else if ( = child)return 1;elsetreenode* tmp2 = find(child);n = tmp2-value.num;while (Parent(tmp2)-value).Name() != gparent) / 查找父结点n *= (Parent(tmp2)-value).Num();tmp2 = Parent(tmp2);return n;void tree:interface1()cout %n;cout % 1、构建医院 %n;cout % 2、包含统计操作 %n;cout % 3、结点及孩子结点输出 %n;cout % 4、浏览医院结构 %n;cout % 5、终止操作 %n;cout %n;cout 请选择。;void tree:show(string n)treenode *tmp = find(n),*tmp2;while (tmp = NULL)int a;string name;cout 该医院不包含该部门(设施)! endl;cout %n;cout % 1、继续查找 %n;cout % 2、返回上层 %n;cout %n;cout a;switch (a)case 1:cout name;tmp = find(name);break;case 2:system(cls);s_treatment();break;system(cls);if (tmp-pc = NULL)cout 该名称单位不包含任何下属设施! endl;elsecout 所包含的下属设施: endl;cout -n;cout | 名称 | 数量|n;cout -n;cout pc)-value endl;cout pc-ls;while (tmp2)cout value endl;cout ls;void tree:s_treatment()string tmp1, tmp2;int n;ifstream inf(data.txt);interface1();cin n;system(cls);while (n != 5)switch (n)case 1:if (!inf)cout 读取失败! tmp1 tmp2 n;hosnode * value = new hosnode(tmp2, n);insert(tmp1, value);cout 读取成功! endl;break;case 2:cout tmp1 tmp2;cout tmp1 包含 tmp2 : count(tmp1, tmp2);cout endl;break;case 3:cout tmp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2023年度中医执业医师能力检测试卷含完整答案详解【易错题】
- 2024中医执业医师考前冲刺试卷及完整答案详解(历年真题)
- 普通行业安全员考试及答案
- 人教版(五四制)6年级数学下册期末试题及参考答案详解(典型题)
- 2025年教育扶贫考试题及答案
- 2025年教师礼仪期末题库及答案
- 2025年咨询工程师真题及参考答案详解(精练)
- 广西地理考试试题及答案
- 2025安全员考试考前冲刺练习题含答案详解【能力提升】
- 2025年化妆讲师考试题及答案
- 2025国新控股(上海)有限公司总经理招聘1人笔试参考题库附答案解析
- 2025国资国企穿透式监管白皮书
- 卒中后抑郁的中医治疗
- 2026届高三地理一轮复习:暑假高考热身模拟试卷(共2套含答案)
- 2025年导游业务考试题库
- 2025-2026学年第一学期学校教导处工作计划:扎根常规提质效稳中求进促提升
- 项目监督管理办法
- 高净值人群消费心态及行为研究报告2025
- 家庭教育中的亲子沟通艺术与策略
- 涉密岗位岗前培训课件
- 胰腺肿瘤WHO分类2025
评论
0/150
提交评论