医院设施基础管理系统C++类树_第1页
医院设施基础管理系统C++类树_第2页
医院设施基础管理系统C++类树_第3页
医院设施基础管理系统C++类树_第4页
医院设施基础管理系统C++类树_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、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& nod

2、e);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/tree

3、node* 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 pri

4、nt();*/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

5、;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

6、 != 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,

7、 *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(treeno

8、de* 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(tm

9、p);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).Nu

10、m();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;co

11、ut % 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 val

12、ue 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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论