图地最小生成树和最短路径.doc

图地最小生成树和最短路径.doc

ID:61825756

大小:46.00 KB

页数:15页

时间:2021-03-21

图地最小生成树和最短路径.doc_第1页
图地最小生成树和最短路径.doc_第2页
图地最小生成树和最短路径.doc_第3页
图地最小生成树和最短路径.doc_第4页
图地最小生成树和最短路径.doc_第5页
资源描述:

《图地最小生成树和最短路径.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、采用图的邻接矩阵方式查找图的最小生成树和最短路径的完整程序代码:#include#include#include#include#include#include#include#include#includeusingnamespacestd;#defineMAXNUM26#defineMAXVALUE32767//矩?阵¨®领¢¨¬接¨®图ª?的Ì?定¡§义°?typedefstruc

2、t{charVertex[MAXNUM];//vertexintEdges[MAXNUM][MAXNUM];//edgeintIstrave[MAXNUM];//flagintVertex_num;//numberofvertexintEdges_num;//numberofedgesintGlaphtype;//0:nodirection;1:direction}Maxtrixgraph;//创ä¡ä建¡§矩?阵¨®领¢¨¬接¨®矩?阵¨®voidCreatmatrixgraph(Maxtrixgraph*G){inti,j,k,we

3、ight;charstart,end;cout<<"pleaseinputtheallvertexinformation:"<Vertex_num;i++){cout<<"the"<>G->Vertex[i];}cout<Edges_num;k++){cout<<"the"<>start>>end>>weight

4、;i=0;j=0;while(G->Vertex[i]!=start){i++;}while(G->Vertex[j]!=end){j++;}G->Edges[i][j]=weight;if(G->Glaphtype==0)G->Edges[j][i]=weight;}}//输º?出?邻¢¨²接¨®矩?阵¨®voidOutmatrix(Maxtrixgraph*G){inti,j;cout<<"Thevertexisfollow:"<Vertex_num;j++)cout<<""<Verte

5、x[j];cout<Vertex_num;i++){cout<Vertex[i];for(j=0;jVertex_num;j++){if(G->Edges[i][j]==MAXVALUE)cout<<"#";elsecout<<""<Edges[i][j];}cout<

6、e{intVertex;//vertexnumberintweight;//quanstructedgenode*next;//thenextedgenode}EdgeNode;//图ª?的Ì?邻¢¨²接¨®链¢¡ä表À¨ª定¡§义°?typedefstruct{EdgeNode*Adjlist[MAXNUM];intvertex_num;intedge_num;intGraphtype;}ListGraph;//生¦¨²成¨¦图ª?的Ì?邻¢¨²接¨®表À¨ªvoidCreatgraph(ListGraph*G){inti,weigh

7、t,start,end;EdgeNode*s;for(i=0;ivertex_num;i++)//clearthenodepointerG->Adjlist[i]=NULL;for(i=0;iedge_num;i++)//inputthe2nodeofeachedgeandweight{cout<<"the"<>start>>end>>weight;s=(EdgeNode*)malloc(sizeof(EdgeNode));s->next=G->Adjlist[start];s->Ve

8、rtex=end;s->weight=weight;G->Adjlist[start]=s;if(G->Graphtype==0){s=(EdgeNode*)malloc(sizeof(EdgeNode))

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。