下载此文档

图的最短路径算法的实现.doc


文档分类:IT计算机 | 页数:约8页 举报非法文档有奖
1/8
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/8 下载此文档
文档列表 文档介绍
图的最短路径算法的实现C语言#include<>#include<>#include<>#defineINF32767#defineMAXV100#defineBUFLEN1024typedefstruct{ charname[100]; charinfo[1000]; }VertexType; typedefstruct {VertexTypevexs[10]; intarcs[100][100]; intvexnum,um; }MGraph; //图结构char**getFile(charfileName[],char*array[],int&count){ FILE*file; charbuf[BUFLEN]; intlen=0; //文件读取的长度 file=fopen(fileName,"rt"); // if(file==NULL) //文件为空的处理办法 { printf("Cannotopenfilestrikeanykeyexit!\n"); exit(1); } while(fgets(buf,BUFLEN,file)) { len=strlen(buf); array[count]=(char*)malloc(len+1); if(!array[count]) break; strcpy(array[count++],buf); } fclose(file); returnarray;}voidgetInfo(int&vex,int&arc,char*array){ charbuf_ch[100]; char*ch[100]; char*tokenp; intstr_count=0,str_len=0; tokenp=strtok(array,""); strcpy(buf_ch,tokenp); while(tokenp!=NULL) { str_len=strlen(tokenp);ch[str_count]=(char*)malloc(str_len+1); strcpy(ch[str_count++],tokenp); tokenp=strtok(NULL,""); } for(inti=0;i<str_count;i++){ if(i%2==1){ ch[i][strlen(ch[i])-1]=0; sscanf(ch[i],"%d",&arc); }else{ sscanf(ch[i],"%d",&vex); } } }MGraphsetVertexTypeInfo(MGraphg,char*arrayVer[]){ intstr_count=0; charbuf_ch[100]; char*ch[100]; char*tokenp; for(inti=0;i<+1&&arrayVer[];i++){ intstr_len=0; tokenp=strtok(arrayVer[i],""); strcpy(buf_ch,tokenp); while(tokenp!=NULL) { str_len=strlen(tokenp); ch[str_count]=(char*)malloc(str_len+1); strc

图的最短路径算法的实现 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数8
  • 收藏数0 收藏
  • 顶次数0
  • 上传人wz_198613
  • 文件大小28 KB
  • 时间2019-06-12