图的最短路径算法的实现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转载请标明出处.