#include
#include
using
namespace std;
const
int max =10;
//限定最大的頂點數
const
int _infinity =
65535
;//定義乙個不可能輸入的數字
class
graph
;//定位(找到字母的下標)
int graph::
locate
(string ch)
}return index;
}//建構函式
graph::
graph
(int v_n,
int e_n)
:vertex_num
(v_n)
,edge_num
(e_n)
//初始化鄰接矩陣
for(i =
0; i <
this
->vertex_num; i++
)else}}
cout <<
"請依次輸入邊相鄰的兩個頂點及邊的權值:"
<< endl;
for(k =
0; k <
this
->edge_num; k++)}
//列印
void graph::
print_graph()
cout << endl;}}
//返回最小值下標
int graph::
min(
int*_distance,
int num)
}return index;
}//dijkstra演算法
void graph::
dijkstra
(int v)
//從源點v出發
else
}//初始化源點
this
->distance[v]=0
;this
->final[v]=1
;//開始主迴圈,每次求得v到乙個頂點的最短路徑,所以迴圈次數比頂點數少一次
for(i =
1; i <
this
->vertex_num; i++)}
}delete
path;
delete
distance;
delete
final;
}int
main()
輸出結果:
Dijkstra 最短路徑演算法C 實現
演算法不用細說,學過資料結構的同仁們都知道,前兩天用到,用c 寫出來了。using system using system.collections.generic using system.text namespace shortedpath static string pathresult new...
dijkstra最短路徑演算法C實現
path記錄上乙個節點 include include define maxlen 10 define large 999 typedef struct int vexnum char vexs maxlen int arcs maxlen maxlen graph void init graph ...
演算法 Python實現dijkstra最短路由
注意 dijkstra演算法不能處理包含負邊的圖 dijkstra演算法實現,有向圖和路由的源點作為函式的輸入,最短路徑最為輸出 defdijkstra graph,src 判斷圖是否為空,如果為空直接退出 if graph is none return none nodes i for i in ...