資源簡介
從一點出發,到其他點的最短距離,先用從鐵路地圖中找出城市,創建文件,構造帶權無向網的鄰接矩陣,用dijkstra算法求出最短路徑
代碼片段和文件信息
#include
#include
#include
#define?SIZE1?20
#define?SIZE2?50
#define?MAX?4000
typedef?struct?Ver{
int?number; //城市序號
char?city[20]; //城市名稱
}Ver;
Ver?VertexType[SIZE1];
typedef?struct?Arc{
int?v0;
int?v1;
int?length; //相鄰接的城市路徑長度
}Arc; //定義邊的類型*/
Arc?ArcCell[SIZE2];
typedef?struct?MGraph{
????Ver?VertexType[SIZE1]; //圖中的頂點,即為城市
????int?arcs[SIZE1][SIZE1]; //圖中的邊,即為城市間的距離
}MGraph; //定義圖的類型
void?save(){
FILE?*fp;
int?i;
if((fp=fopen(“ArcCell.txt““wb“))==NULL){
printf(“cannot?open?file\n“);
return;
}
for(i=0;i if(fwrite(&ArcCell[i]sizeof(struct?Arc)1fp)!=1)
printf(“flie“);
fclose(fp);
}
void?Create(MGraph?&G){
int?ij;
for(i=0;i for(j=0;j
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2767??2007-12-01?13:09??shortpath.cpp
?????文件????????600??2007-11-29?17:02??ArcCell.txt
?????文件????????480??2007-11-29?15:30??VertexType.txt
-----------?---------??----------?-----??----
?????????????????3847????????????????????3
- 上一篇:eclipse文件打開插件源碼
- 下一篇:flashBuild4.7序列號生成器
評論
共有 條評論