




下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、數據結構實驗報告-6 -、目的與要求1)掌握AOE網的鄰接表存儲結構表示及創建算法的c語言實現;2)理解AOE網的拓撲排序算法(算法7.12)的實現原理及應用;3)掌握AOE網關鍵路徑的計算算法(算法 7.13 , 7.14)及C語言實現與應用;4)按照實驗題目要求獨立正確地完成實驗內容(提交程序清單及相關實驗數據與運行結果);5)認真書寫實驗報告,并按時提交。二、實驗內容題目: 圖的應用實驗一一計算 AOER的關鍵路徑1所示內容:按照圖的“鄰接表”存儲結構表示AOER,實現求其關鍵路徑的算法,并驗證如下圖AOE網的關鍵路徑。三、實驗步驟與源程序# include <iostream.h
2、> # include <stdlib.h># define max_vertex_num 50# define maxvalue 32760# define NULL 0 typedef struct edgenodeint adjvex;struct edgenode *next;int weight; edgenode,* pedgenode;typedef struct vnodeint data;struct edgenode *firstarc;vnode,adjlistmax_vertex_num,* pvnode;void creatgraphadlist(p
3、vnode &pn,int n)/依次輸入頂點偶對,建立無向圖鄰接表edgenode *p;int i,j,k,wei;i=j=1;pn=(pvnode)malloc(n+1)*sizeof(vnode);for(k=1;k<=n;k+)pnk.firstarc=NULL;/初始化每個鏈表為空for(int f=1;!(i=0&&j=0);) cout<<"Please input number of-"<<f<<"-vertices of an arc,End with (0,0):"
4、;cin>>i>>j;if(i>0&&i<=n&&j>0&&j<=n)p=(edgenode *)malloc(sizeof(edgenode);/生成一個節點p->adjvex=j;/ 為節點j的序號附值為jp->next=pni.firstarc;/將該p節點作為第i個鏈表的第一個節點插入pni之后 pni.firstarc=p;/ 將接點j作為第一個接點插入連表i的后面 cout<<"Please enter the weight of the edge:&q
5、uot; cin>>wei;p->weight =wei; f+; else if(i=0&&j=0) ;/什么也不做 else cout<<"Please re-enter .n" /for cout<<"n"void findindegree(pvnode pn,int n,int *deg)for(int i=1;i<=n;i+) 第 0 個元素不用degi=0;/對數組進行初始化,全部置0pedgenode pk;for(i=1;i<=n;i+)/對鄰接表進行遍歷pk=pni.
6、firstarc;for(;pk;pk=pk->next) degpk->adjvex+;/ 數組相應元素自增存放各點發生的最早時刻(全局變量)存放拓撲序列各頂點的棧(全局變量)int vemax_vertex_num;/ int stmax_vertex_num;/ int top2;/( 全局變量)void topologicalorder(pvnode pn,int n,int *tt)int indegreemax_vertex_num;/該數組存放各頂點的入度int ssmax_vertex_num;/ 設計棧ss,用以存放入度為0的頂點的信息 int *deg;int
7、j;deg=indegree;findindegree(pn,n,deg);for(int i=1;i<=n;i+)/ve0 不用vei=0;/ 初始化int top1;top1=top2=0;/top1 和top2為棧頂指針,分別指向棧ss和tt ,初始值均為0(即棧為空)for(i=1;i<=n;i+)if(!indegreei)/ 若頂點i入度為0,則進棧ss+top1=i;int count=0;/對輸出頂點計數cout<<"The topological order of the graph is:n"while(top1)/ 若ss非空,
8、進入循環j=sstop1-;/i 出棧cout<<j<<" "/ 輸出i頂點序號tt+top2=j;/將 i 進入 tt 棧count+;/ 計數for(pedgenode p=pnj.firstarc ;p;p=p->next )int k=p->adjvex ;indegreek-;/對每一個以i為弧尾的頂點,將他們的入度減1if(!indegreek)ss+top1=k;/如果減為0,則入棧。因為若入度為x,必然要自減x次才能如 棧,所以可以避免重復進棧if(vej+p->weight)>vek)vek=vej+p-&g
9、t;weight;/顯然此時j是k的前驅,且vej是j發生的最早時間,若if(count<n)cout<<"nThere are rings in the graph -error!n"return;cout<<"n"<<endl;cout<<"The earliest time of each vertex :"<<endl;for(i=1;i<=n;i+)cout<<"vertex("<<i<<"
10、;)earliest time is:"<<vei<<endl;cout<<"n"<<endl;void criticalpath(pvnode pn,int n,int *tt)int j,k,dut,ee,el,tag,f=1;pedgenode p;int vlmax_vertex_num;/存放各點發生的最遲時刻for(int i=1;i<=n;i+)vli=ven;/ 用頂點n的最早時間初始化各頂點的最遲時間*/while(top2)j=tttop2-;/ 出棧for(p=pnj.firstarc ;
11、p;p=p->next )k=p->adjvex ;dut=p->weight;if(vlk-dut)<vlj)vlj=vlk-dut;cout<<"After calculation, the key path of the figure is as follows n"for(j=1;j<=n;j+)for(p=pnj.firstarc ;p;p=p->next )k=p->adjvex ;dut=p->weight ;ee=vej;el=vlk-dut;if(ee=el) /ee=el,說明是關鍵活動cout
12、<<"The"<<f+<<"Key activities are:"<<j<<"-"<<k<<endl;/打印關鍵活動int main()int n,*tt;pvnode pn;tt=st;cout<<"Please enter the number of vertices of the graph :" cin>>n;cout<<""<<endl;creatgra
13、phadlist(pn,n);topologicalorder(pn,n,tt);criticalpath(pn,n,tt);return 0;四、測試數據與實驗結果C VJirido q l 邑產 1lense enter thr number of vertices of the graphease enseedse easeertse erise rsiqp戶 nascEC立足 PilRP niisc 巳日 ease 戶 flQPUdEU edeinputnumber of 1 vertices of narcXnddth(0.0);12enierthe ”ioht of the edg
14、e: 6inputruin her nt'?-vrrt i c&s of anarc hFndwith(配 tn:25Enterthe weigh! of the adge;linputnumber of 3-vertices ofeirc, EndML th(0W):13pnlerthp wp i ght of thp pdgft 4.inpiiltMJmbr of-4-ver 1 ic&s of dnfire pFndtj i 1 li(CM):35enterthe weiqht of the edcie: 1inputnunber of-5 vertices of
15、 wncirc PEndjith(0f0):51enierthe weight of the d()c:9inpulnumber ol-6-verlices of anarc.Endfuilli(0.OL73enterthe weight of the edge;2i npidrniiihpr of -7-vertics nf nnnrc PFnd5 th(0 0):5Renterthe weight of the adqc:7inputnumber ot-8-vcrlices of anarc.EndtjiUi(0.0);8yenterthe weight of the edge:4i np
16、iitr>imbpr of -9-vert iof anfircpFndwii th(0,0):1&enterthe tveight of the edge;binputnunber ol-10-uert ices of ari arc.tnc1 with(0,0);h6enierthe weight of the edge:2i npiitminber of -11 -yerti res of nr arc,Fnd wi th(nforfi genterthe neioht of the edge;4inpu Inumber ol-12-vertices of drarc.En
17、d withwu):E1日Pl電3金 i nput nuiKbr of 12 vert i ces; of an orc .End 叫ith (C, 0 h 8 6The 1orological order of the grnph ist 12 3 3 7 4 6 8 9The eflrI iest t i ne tex(1 Jear I iestyertext?)earliest vertex(9earliest verteKUierirl jest uertex(5)earliest uertex(6)earliest wertex(7)earliest ver tex(8)tjrlit
18、s t uertex(9)earliestn>f f?曰二h vertex : tIne is:0 tiite i零:6 tine is;fttine is:5 iiMe is:7 tike is:7ti.Me is: 16 t iae is:14 tine is:18fitter calcjlatian, ThelKeyi activities The2KBy activities TheSKey activities TheKey aciivities The5Key activities Ihn6K叫 nr t i u11 iesthn k(?y path cf th何 fiyiiro is as foilowsare :1 2<*ra;25arQ: 5-ftore: 5 7are: 79enter thd riiiKiher 口f,0rtirRE nf the 口r即卜rirn田9五、結果分析與實驗體會本次實驗基本掌握了 AOE網的系列概念及用法,也基本完成代碼的調試與運行,具體實驗步驟
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 社區文化活動的組織與推廣考核試卷
- 紙張加工中的表面涂層結構設計考核試卷
- 玩具設計的創新材料應用考核試卷
- 電視機銷售渠道拓展與電商平臺合作考核試卷
- 竹材采運市場營銷渠道拓展與客戶關系考核試卷
- 紡織企業全面質量管理考核試卷
- 碳酸飲料企業社會責任實踐考核試卷
- 毛條與毛紗線加工過程中的環境保護與節能減排考核試卷
- 宜春幼兒師范高等專科學校《數學學科與教學指導》2023-2024學年第二學期期末試卷
- 四川城市職業學院《安全與倫理》2023-2024學年第二學期期末試卷
- 路面附屬工程施工組織設計
- 規劃課題申報范例:高職院校特殊群體學生心理問題分析及教育案例研究(附可修改技術路線圖)
- (2025新版)建設工程安全防護、文明施工措施費用支付計劃
- 2024下半年軟考信息安全工程師考試真題-及答案-打印
- 中華人民共和國能源法
- 小學五年級期中家長會課件
- 2025年中考語文二輪復習名著思維導圖專題課件《經典常談》課件
- 化學工程概述-化學工程師的角色和職責
- 頸椎病 課件教學課件
- 2023-2024學年北京一零一中高一下學期期中考試化學試題(合格考)(含答案)
- 眩暈中醫課件
評論
0/150
提交評論