




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、C+類樹醫(yī)院設(shè)施管理樹旳應(yīng)用,記錄任意兩個結(jié)點之間旳結(jié)點個數(shù),支出給定結(jié)點旳子結(jié)點,瀏覽整個醫(yī)院旳構(gòu)造,C+,類 ,樹,醫(yī)院設(shè)施管理,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; /父結(jié)點public:hosnode value;treenode* pc; /最左邊子結(jié)點treenode* ls; /左兄弟節(jié)點treenode* rs; /右兄弟節(jié)點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 | 名稱 | 數(shù)量 |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) / 查找父結(jié)點n *= (Parent(tmp2)-value).Nu
10、m();tmp2 = Parent(tmp2);return n;void tree:interface1()cout %n;cout % 1、構(gòu)建醫(yī)院 %n;cout % 2、涉及記錄操作 %n;cout % 3、結(jié)點及孩子結(jié)點輸出 %n;cout % 4、瀏覽醫(yī)院構(gòu)造 %n;cout % 5、終結(jié)操作 %n;cout %n;cout 請選擇。;void tree:show(string n)treenode *tmp = find(n),*tmp2;while (tmp = NULL)int a;string name;cout 該醫(yī)院不涉及該部門(設(shè)施)! endl;cout %n;co
11、ut % 1、繼續(xù)查找 %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 該名稱單位不涉及任何下屬設(shè)施! endl;elsecout 所涉及旳下屬設(shè)施: endl;cout -n;cout | 名稱 | 數(shù)量|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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 時尚雜志插畫師聘用合同
- 內(nèi)科品管圈護(hù)理實踐應(yīng)用
- 大學(xué)生如何報考部隊文職
- 2024貿(mào)易公司簡介范文大全(35篇)
- 直腸癌患者術(shù)后健康宣教
- 廣發(fā)銀行工作總結(jié)專用
- 心外護(hù)理工作流程優(yōu)化
- 護(hù)理實踐指南:手術(shù)室人員管理
- 教育家學(xué)術(shù)體系解析
- 創(chuàng)造力與想象力培養(yǎng)課件
- 荊州中學(xué)2024-2025高二學(xué)年下學(xué)期6月月考 英語試卷
- 2025年上海市初中學(xué)業(yè)水平考試數(shù)學(xué)試卷真題(含答案)
- 有限空間作業(yè)通風(fēng)時間專題
- 廣東省廣州市天河外國語學(xué)校2025年七年級英語第二學(xué)期期末綜合測試模擬試題含答案
- 2025年中國氯化聚醚項目投資計劃書
- 2025年公務(wù)員綜合素質(zhì)能力考試卷及答案
- TSZGFA-信息通信基礎(chǔ)設(shè)施工程規(guī)劃設(shè)計規(guī)范
- 成都市高新區(qū)2023年七年級《歷史》下冊期末試卷與參考答案
- 化工智能控制技術(shù)-形考任務(wù)4(預(yù)備知識:第十~十三章;分值100分;不需輔導(dǎo)老師評閱)測驗-國開-參考資料
- 螞蟻花唄對大學(xué)生消費行為的實證分析
- 儲能專業(yè)知識考試試題及答案
評論
0/150
提交評論