资源简介
djksrla最短路径算法(C++实现)
代码片段和文件信息
#include
using namespace std;
const int maxint = 32767;
const int maxnode = 101;
int dis[maxnode];
int c[maxnode][maxnode];
int prev[maxnode];
int n line;
void dijkstra(int n int v int *prev int dis[maxnode] int c[maxnode][maxnode]);
void searchPath(int *prevint v int u);
void main()
{
cin >> n;
cin >> line;
int p q len;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j)
{
c[i][j] = maxint;
}
}
for (i = 1; i <= line; ++i)
{
cin >> p >> q >> len;
if (len < maxint)
{
c[p][q] = len;
c[q][p] = len;
}
}
for (i = 1; i <= n; ++i)
{
dis[i] = maxint;
}
dijkstra(n 1 prev dis c);
cout << dis[n] << endl;
searchPath(prev 1 n);
}
void dijkstra(int n int v int *prev int dis[maxnode] int c[maxnode][maxnode])
{
bool s[maxint];
for
- 上一篇:一个完整的C++ odbc连接数据库
- 下一篇:使用c++实现用户登录界面
评论
共有 条评论