




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上精选优质文档-倾情为你奉上专心-专注-专业专心-专注-专业精选优质文档-倾情为你奉上专心-专注-专业#include#include#include #include #include#includeusing namespace std;class hosnode/医院节点 friend class Tree; hosnode* father;/父亲指针; hosnode* left_child;/左孩子 hosnode* right_brother;/右兄弟 string name;/节点名称 int n;/数量public: hosnode(string nn,
2、int b) name=nn; n=b; string getname() return name; int get_n() return n; ;class Tree/结构类(这里为医院结构类) hosnode* head;public: Tree(string name,int n) head=new hosnode(name,n); head-left_child=0; head-right_brother=0; head-father=0; hosnode *find(string name) hosnode* temp=head; if(name=temp-name)return t
3、emp; queue a; a.push(temp); while(!a.empty() temp=a.front()-left_child;/出队列 a.pop(); while(temp!=0) a.push(temp); if(name=temp-name)return temp; temp=temp-right_brother; return 0; bool insert(string father,string child,int n) hosnode* temp=find(father); if(temp-left_child=0) temp-left_child=new hosn
4、ode(child,n); temp-left_child-right_brother=0; temp-left_child-father=temp; temp-left_child-left_child=0; else temp=temp-left_child; while(temp-right_brother!=0) temp=temp-right_brother; temp-right_brother=new hosnode(child,n); temp-right_brother-right_brother=0; temp-right_brother-father=find(fathe
5、r); temp-right_brother-left_child=0; return 1; int get_number(string big,string small)/ hosnode* p1=find(big); hosnode* p2=find(small); int sum=1; while(p2!=0&p2!=p1) sum*=p2-n; p2=p2-father; if(p2=0) return 0; else return sum; hosnode * childs(string name) hosnode * temp=find(name); if(temp=0)retur
6、n 0; else coutnameleft_child; if(temp=0)cout无; while(temp!=0) coutnameright_brother; coutname); queue a; a.push(temp); while(!a.empty() temp=a.front()-left_child;/出队列 a.pop(); while(temp!=0) a.push(temp); childs(temp-name); temp=temp-right_brother; ;int main() int flag = 1 ; string p,c;Tree a(医院,1);
7、a.insert(医院,楼层,10);a.insert(楼层,配楼,4);a.insert(楼层,中央大厅,1);a.insert(中央大厅,电视,1);a.insert(中央大厅,沙发,2);a.insert(配楼,长走廊,2);a.insert(配楼,走廊连接,1);a.insert(走廊连接,库房,5);a.insert(长走廊,病房,21);a.insert(病房,卫生间,1);a.insert(病房,插座,4);a.insert(病房,病床,2);a.insert(卫生间,洗脸盆,1);a.insert(卫生间,座便器,1);a.insert(插座,插口,2);a.insert(插座,面板,1); while (flag) cout输入要查找的父节点和子节点 p c; couta.get_number(p,c)endl; cout继续输入1,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论