管道铺设施工的最佳方案 完整程序代码Word下载.docx

上传人:wj 文档编号:235495 上传时间:2023-04-28 格式:DOCX 页数:7 大小:83.30KB
下载 相关 举报
管道铺设施工的最佳方案 完整程序代码Word下载.docx_第1页
第1页 / 共7页
管道铺设施工的最佳方案 完整程序代码Word下载.docx_第2页
第2页 / 共7页
管道铺设施工的最佳方案 完整程序代码Word下载.docx_第3页
第3页 / 共7页
管道铺设施工的最佳方案 完整程序代码Word下载.docx_第4页
第4页 / 共7页
管道铺设施工的最佳方案 完整程序代码Word下载.docx_第5页
第5页 / 共7页
管道铺设施工的最佳方案 完整程序代码Word下载.docx_第6页
第6页 / 共7页
管道铺设施工的最佳方案 完整程序代码Word下载.docx_第7页
第7页 / 共7页
亲,该文档总共7页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

管道铺设施工的最佳方案 完整程序代码Word下载.docx

《管道铺设施工的最佳方案 完整程序代码Word下载.docx》由会员分享,可在线阅读,更多相关《管道铺设施工的最佳方案 完整程序代码Word下载.docx(7页珍藏版)》请在冰点文库上搜索。

管道铺设施工的最佳方案 完整程序代码Word下载.docx

stdlib.h"

#defineMAX_VERTEX_NUM20

typedeffloatWeightType;

typedefstructArcNode{

intadjvex;

WeightTypeweight;

structArcNode*nextarc;

}ArcNode;

typedefstructVertexNode{

chardata;

ArcNode*firstarc;

}VertexNode,AdjList[MAX_VERTEX_NUM];

typedefstruct{

AdjListvertices;

intvexnum,arcnum;

intkind;

}ALGraph;

intLocateVex(ALGraphG,charv)

{

inti;

for(i=0;

i<

G.vexnum;

i++)

{

if(G.vertices[i].data==v)

returni;

}

return-1;

}

voidCreateGraph(ALGraph&

G)

inti,j,k;

charvi,vj;

ArcNode*p,*q;

std:

:

cout<

<

"

请输入顶点个数,边数和图的类型:

\n"

;

cin>

>

G.vexnum>

G.arcnum>

G.kind;

for(i=0;

std:

请输入各个顶点:

G.vertices[i].data;

G.vertices[i].firstarc=NULL;

for(k=0;

k<

G.arcnum;

k++)

请输入两顶点和其边的权值:

vi>

vj>

weight;

i=LocateVex(G,vi);

j=LocateVex(G,vj);

p=(ArcNode*)malloc(sizeof(ArcNode));

p->

adjvex=j;

weight=weight;

nextarc=G.vertices[i].firstarc;

G.vertices[i].firstarc=p;

if(G.kind==2)

{

q=(ArcNode*)malloc(sizeof(ArcNode));

q->

adjvex=i;

weight=p->

weight;

nextarc=G.vertices[j].firstarc;

G.vertices[j].firstarc=q;

}

intMinEdge(WeightTypelowcost[],intvexmun)

inti,k;

WeightTypej;

k=0;

while(lowcost[k]==0)

k++;

j=lowcost[k];

for(i=k+1;

vexmun;

if(lowcost[i]!

=0&

&

lowcost[i]<

j)

j=lowcost[i];

k=i;

returnk;

voidPrim(ALGraphG,intv0,intadjvex[])

WeightTypelowcost[MAX_VERTEX_NUM];

ArcNode*p;

if(i!

=v0)

lowcost[i]=999;

adjvex[i]=v0;

p=G.vertices[v0].firstarc;

while(p)

lowcost[G,p->

adjvex]=p->

p=p->

nextarc;

lowcost[v0]=0;

k=MinEdge(lowcost,G.vexnum);

if(k>

=G.vexnum)

return;

("

<

"

adjvex[k]<

),"

lowcost[k]<

'

\n'

lowcost[k]=0;

p=G.vertices[k].firstarc;

while(p)

if(p->

weight<

lowcost[p->

adjvex])

{

adjvex[p->

adjvex]=k;

lowcost[p->

}

p=p->

intmain()

intadjvex[MAX_VERTEX_NUM];

ALGraphG;

G.kind=2;

CreateGraph(G);

Prim(G,0,adjvex);

return0;

/*测试数据

9152

A

B

C

D

E

F

G

H

I

AB32.8

AI18.2

AH12.1

AC44.6

BC5.9

CD21.3

CE41.1

CG56.4

DE67.3

DF98.7

EF85.6

EG10.5

HG52.5

IH8.7

IF79.2

*/

页脚内容

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2