电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

图的最短路径算法的实现

8页
  • 卖家[上传人]:jiups****uk12
  • 文档编号:90650892
  • 上传时间:2019-06-14
  • 文档格式:DOC
  • 文档大小:56.04KB
  • / 8 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1、图的最短路径算法的实现C语言#include#include#include#define INF 32767#define MAXV 100#define BUFLEN 1024typedef struct char name100;char info1000; VertexType;typedef struct VertexType vexs10; int arcs100100;int vexnum,arcnum; MGraph;/图结构 char* getFile(char fileName,char *array,int &count)FILE *file;char bufBUFLEN;int len=0;/文件读取的长度 file=fopen(fileName,rt);/打开graph.txt的信息 if(file=NULL)/文件为空的处理办法 printf(Cannot open file strike any key exit!n);exit(1);while(fgets(buf,BUFLEN,file) len=strlen(buf); arraycount=(cha

      2、r*)malloc(len+1); if(!arraycount) break; strcpy(arraycount+,buf);fclose(file);return array;void getInfo(int &vex,int &arc,char *array)char buf_ch100;char *ch100; char *tokenp;int str_count=0,str_len=0;tokenp=strtok(array, );strcpy(buf_ch,tokenp);while(tokenp!=NULL)str_len=strlen(tokenp); chstr_count=(char*)malloc(str_len+1); strcpy(chstr_count+,tokenp); tokenp=strtok(NULL, );for(int i=0;istr_count;i+)if(i%2=1)chistrlen(chi)-1=0;sscanf(chi,%d,&arc);elsesscanf(chi,%d,&vex); MGraph setVertexTypeInf

      3、o(MGraph g,char *arrayVer)int str_count=0;char buf_ch100;char *ch100;char *tokenp;for(int i=0;ig.vexnum+1&arrayVerg.vexnum;i+)int str_len=0;tokenp=strtok(arrayVeri, );strcpy(buf_ch,tokenp);while(tokenp!=NULL) str_len=strlen(tokenp); chstr_count=(char*)malloc(str_len+1); strcpy(chstr_count+,tokenp);tokenp=strtok(NULL, );for(int i1=2;i1str_count;i1+)if(i1%2=1)chi1strlen(chi1)-1=0;strcpy(g.vexsi1/2-1.info,chi1);elsestrcpy(g.vexsi1/2-1.name,chi1);return g;/设置无向图的基本信息 MGraph setMGraphInfo(MGraph g,ch

      4、ar *arrayMGraph,int &count)int str_count=0;char buf_ch100;char *ch100;char *tokenp;for(int i4=g.vexnum+1;i4count;i4+)int str_len=0;tokenp=strtok(arrayMGraphi4, );strcpy(buf_ch,tokenp);while(tokenp!=NULL) str_len=strlen(tokenp); chstr_count=(char*)malloc(str_len+1); strcpy(chstr_count+,tokenp);tokenp=strtok(NULL, );char *info8;/需要匹配的字符串集合 for(int i2=0;i2g.vexnum;i2+)infoi2=g.vexsi2.name;int G5050;/邻接矩阵初始化 for(int i3=0;i3g.vexnum;i3+)for(int j=0;jg.vexnum;j+)Gi3j=INF;int temp100=0;/存储距离信息 int temp

      5、_count=0;/距离计数器 int templeft100=0;/起始地址的代号信息 int templeft_count=0;/起始地址计数器 int tempright100=0;/终点地址的代号信息 int tempright_count=0;/终点地址的计数器 for(int k=0;kstr_count;k+)if(k%3=0)for(int m=0;mg.vexnum;m+)if(strcmp(infom,chk)=0)templefttempleft_count+=m;else if(k%3=1)for(int m=0;mg.vexnum;m+)if(strcmp(infom,chk)=0)temprighttempright_count+=m;else if(k%3=2)chkstrlen(chk)-1=0;sscanf(chk,%d,&temptemp_count+);for(int i5=0;i5temp_count;i5+)Gtemplefti5temprighti5=tempi5;for(int i6=0;i6g.vexnum;i6+)/建立图的邻接矩阵fo

      6、r(int j=0;jg.vexnum;j+)g.arcsi6j=Gi6j;return g;void DispMat(MGraph g)int i,j;for(i=0;ig.vexnum;i+)for (j=0;j,g.vexsk.name);ppath(g,path,k,j);void DisPath(MGraph g,int AMAXV,int pathMAXV,int i,int j)if (Aij=INF)if (i!=j) printf(从 %s 到 %s 没有路径n,g.vexsi.name,g.vexsj.name);elseprintf(%s-,g.vexsi.name);ppath(g,path,i,j);printf(%s,g.vexsj.name);printf(t路径长度为:%dn,Aij); void Floyd(MGraph g,int p,int q)/弗洛伊德算法int AMAXVMAXV,pathMAXVMAXV;int i,j,k,n=g.vexnum;for (i=0;in;i+)for (j=0;jn;j+) Aij=g.arcsij;pathij=-1;for (k=0;kn;k+) for (i=0;in;i+) for (j=0;j(Aik+Akj) Aij=Aik+Akj; pathij=k; printf(最短路径为:n);DisPath(g,A,path,p,q); /输出最短路径int main()int vex,arc;printf( 欢迎来到江西理工大学 n);printf( n);MGraph g;/图的定义char *array1;/存储顶点和边数数据信息 char *arrayVer10;/存储地点信息 char *arrayMGraphMAXV;/存储关于图的信息 int count=0;char fileName=D:数据结构shujujiegouyigraph.txt;

      《图的最短路径算法的实现》由会员jiups****uk12分享,可在线阅读,更多相关《图的最短路径算法的实现》请在金锄头文库上搜索。

      点击阅读更多内容
    最新标签
    信息化课堂中的合作学习结业作业七年级语文 发车时刻表 长途客运 入党志愿书填写模板精品 庆祝建党101周年多体裁诗歌朗诵素材汇编10篇唯一微庆祝 智能家居系统本科论文 心得感悟 雁楠中学 20230513224122 2022 公安主题党日 部编版四年级第三单元综合性学习课件 机关事务中心2022年全面依法治区工作总结及来年工作安排 入党积极分子自我推荐 世界水日ppt 关于构建更高水平的全民健身公共服务体系的意见 空气单元分析 哈里德课件 2022年乡村振兴驻村工作计划 空气教材分析 五年级下册科学教材分析 退役军人事务局季度工作总结 集装箱房合同 2021年财务报表 2022年继续教育公需课 2022年公需课 2022年日历每月一张 名词性从句在写作中的应用 局域网技术与局域网组建 施工网格 薪资体系 运维实施方案 硫酸安全技术 柔韧训练 既有居住建筑节能改造技术规程 建筑工地疫情防控 大型工程技术风险 磷酸二氢钾 2022年小学三年级语文下册教学总结例文 少儿美术-小花 2022年环保倡议书模板六篇 2022年监理辞职报告精选 2022年畅想未来记叙文精品 企业信息化建设与管理课程实验指导书范本 草房子读后感-第1篇 小数乘整数教学PPT课件人教版五年级数学上册 2022年教师个人工作计划范本-工作计划 国学小名士经典诵读电视大赛观后感诵读经典传承美德 医疗质量管理制度 2 2022年小学体育教师学期工作总结
     
    收藏店铺
    关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
    手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
    ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.