欢迎来到天天文库
浏览记录
ID:11284125
大小:32.50 KB
页数:7页
时间:2018-07-11
《有向图邻接表 最短路径》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、有向图最短距离#include#defineINFINITY10000#defineTRUE1#defineFALSE0#defineVERTEX_NUM6typedefstructGraph{charvexs[VERTEX_NUM];intarcs[VERTEX_NUM][VERTEX_NUM];intvexnum;intarcnum;}Graph;voidShortestPath(Graphg,intv0,intp[][VERTEX_NUM],intd[]){intv;intw;intmi
2、n;inti,j;intfinal[VERTEX_NUM];for(v=0;v3、[w]){if(d[w]-1&&j4、td[VERTEX_NUM];intv0;g.vexs[0]='A',g.vexs[1]='B',g.vexs[2]='C',g.vexs[3]='D',g.vexs[4]='E',g.vexs[5]='F';for(i=0;i5、.arcs[3][5]=10,g.arcs[4][3]=20,g.arcs[4][5]=60;g.vexnum=g.arcnum=VERTEX_NUM;for(i=0;i6、printf("Path%cto%c:",g.vexs[v0],g.vexs[i]);if(p[i][v0]!=-1){for(j=0;p[i][j]!=-1;j++){if(j!=0)printf("→");printf("%c",g.vexs[p[i][j]]);}printf("");}printf("Length:%d",d[i]);printf("");}}
3、[w]){if(d[w]-1&&j4、td[VERTEX_NUM];intv0;g.vexs[0]='A',g.vexs[1]='B',g.vexs[2]='C',g.vexs[3]='D',g.vexs[4]='E',g.vexs[5]='F';for(i=0;i5、.arcs[3][5]=10,g.arcs[4][3]=20,g.arcs[4][5]=60;g.vexnum=g.arcnum=VERTEX_NUM;for(i=0;i6、printf("Path%cto%c:",g.vexs[v0],g.vexs[i]);if(p[i][v0]!=-1){for(j=0;p[i][j]!=-1;j++){if(j!=0)printf("→");printf("%c",g.vexs[p[i][j]]);}printf("");}printf("Length:%d",d[i]);printf("");}}
4、td[VERTEX_NUM];intv0;g.vexs[0]='A',g.vexs[1]='B',g.vexs[2]='C',g.vexs[3]='D',g.vexs[4]='E',g.vexs[5]='F';for(i=0;i5、.arcs[3][5]=10,g.arcs[4][3]=20,g.arcs[4][5]=60;g.vexnum=g.arcnum=VERTEX_NUM;for(i=0;i6、printf("Path%cto%c:",g.vexs[v0],g.vexs[i]);if(p[i][v0]!=-1){for(j=0;p[i][j]!=-1;j++){if(j!=0)printf("→");printf("%c",g.vexs[p[i][j]]);}printf("");}printf("Length:%d",d[i]);printf("");}}
5、.arcs[3][5]=10,g.arcs[4][3]=20,g.arcs[4][5]=60;g.vexnum=g.arcnum=VERTEX_NUM;for(i=0;i6、printf("Path%cto%c:",g.vexs[v0],g.vexs[i]);if(p[i][v0]!=-1){for(j=0;p[i][j]!=-1;j++){if(j!=0)printf("→");printf("%c",g.vexs[p[i][j]]);}printf("");}printf("Length:%d",d[i]);printf("");}}
6、printf("Path%cto%c:",g.vexs[v0],g.vexs[i]);if(p[i][v0]!=-1){for(j=0;p[i][j]!=-1;j++){if(j!=0)printf("→");printf("%c",g.vexs[p[i][j]]);}printf("");}printf("Length:%d",d[i]);printf("");}}
此文档下载收益归作者所有